Reputation: 43589
I have a string: The quick brown fox jumped over the lazy dogs.
I want to insert a ,
(comma and space) into a random spot where there currently is just a (space). How can I accomplish this?
Upvotes: 0
Views: 39
Reputation: 386746
Another way:
var string = 'The quick brown fox jumped over the lazy dogs.',
array = string.split(' '),
i = Math.random() * (array.length - 1) | 0;
array[i] += ',';
string = array.join(' ');
document.write(string);
Upvotes: 1