gpt4 book ai didi

javascript - 使用 JavaScript 创建虚拟文本

转载 作者:行者123 更新时间:2023-11-28 11:11:57 24 4
gpt4 key购买 nike

我想使用 JavaScript 创建 1000 个单词的虚拟文本。我的想法是使用这样的数组

var words =["The sky", "above", "the port","was", "the color of television", "tuned", "to", "a dead channel", ".", "All", "this happened", "more or less","." ,"I", "had", "the story", "bit by bit", "from various people", "and", "as generally", "happens", "in such cases", "each time", "it", "was", "a different story","." ,"It", "was", "a pleasure", "to", "burn"];

然后使用javascript随机输出1000个单词。我该如何使用 JavaScript 来做到这一点?还有其他方法可以做到吗?

最佳答案

看看这个

var words =["The sky", "above", "the port","was", "the color of television", "tuned", "to", "a dead channel", ".", "All", "this happened", "more or less","." ,"I", "had", "the story", "bit by bit", "from various people", "and", "as generally", "happens", "in such cases", "each time", "it", "was", "a different story","." ,"It", "was", "a pleasure", "to", "burn"];
var text = [];
var x = 1000;
while(--x) text.push(words[Math.floor(Math.random() * words.length)]);
document.write(text.join(" "))

引用: SO | Getting random value from an array

关于javascript - 使用 JavaScript 创建虚拟文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34123706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com