I have a function that needs to append a sequence of numbers (starting with 1) at the end of each word in the string. Here is my function:
function insertNum(str) {
var word = new Array();
word = str.split(" ");
return src[0] + "1 " + src[1] + "2 " + src[2] + "3 " + src[3];
}
insertNum("word word word word."); // return "word1 word2 word3 word4."
insertNum("word word word."); // return "word1 word2 word3."
This should do it…
jsFiddle.