我有一个字符串:The quick brown fox jumped over the lazy dogs.我想在随机只有一个,(空格)的位置插入一个(逗号和空格)。我该怎么做?

最佳答案

另一种方式:



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);

10-05 20:36
查看更多