I would like to replace the string "The quick brown fox jumps over the lazy dog" with the string "The1 quick2 brown3 fox4 jumps5 over6 the7 lazy8 dog9".
Is there an cleaner, more elegant, sexier way?
String.prototype.concatWordNumber = function() {
var myArray = this.split(' ');
var myString = "";
for (var i=0, len = myArray.length; i<len; i++)
{
myString += myArray[i]+[i+1]+ " " ;
}
return myString;
}
var text = "The quick brown fox jumps over the lazy dog";
console.log(text.concatWordNumber());