我正在尝试获取JavaScript代码以从数组中随机选择文本字符串。到目前为止,这是我所拥有的,但是似乎没有用,请多多帮助。不知道这是否重要,但这是针对网站的。
var myArray = ['One does not simply click the acorn'.'acorn spices all the rage with Martha Stewart', 'Once more into the acorn tree my friends','Acornbook launches as first acorn based social media'];
var rand = myArray[Math.floor(Math.random() * myArray.length)];
var postmessage = + myArray;
最佳答案
您正在使用点“。”在myArray的前两个元素之间而不是逗号“,”。
您应在此处使用逗号,如下所示。
var myArray = ['One does not simply click the acorn','acorn spices all the rage with Martha Stewart', 'Once more into the acorn tree my friends','Acornbook launches as first acorn based social media'];