【发布时间】:2022-08-04 22:21:11
【问题描述】:
有什么方法可以让我立即从行中获取随机的单个结果并将其输出,而无需推送到 healthArray?
我的主要目标是提高性能,因为该行最多可以包含 200 多个文本,我不希望它继续推送到数组。
let randomFact;
let healthArray = []
$(\".round-number\")
.find(\"h3\")
.each(function (i, el) {
let row = $(el).text().replace(/(\\s+)/g, \" \");
row = $(el)
.text()
.replace(/[0-9]+\\. /g, \"\")
.trim();
healthArray.push(row);
});
randomFact =
healthArray[
Math.floor(Math.random() * healthArray.length)
].toString();
标签: javascript jquery