您现在的位置是:网站首页>文章详情文章详情
js从数组中随机生成指定长度的数组
inlike2019-11-23【 原创文章 】 浏览(1440) 评论(0) 喜欢(18)
简介js从数组中随机生成指定长度的数组
如题:js从数组中随机生成指定长度的数组
function getRandomArrayElements(arr, count) {
var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index; while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
} return shuffled.slice(min);
}
标签
上一篇:js向指定元素添加标签元素
下一篇:XPath高级用法
相关文章
本栏推荐
标签云
猜你喜欢
站点信息
- 建站时间:2019-5-24
- 网站程序:like in love
- 主题模板:《今夕何夕》
- 文章统计:104条
- 文章评论:***条
- 微信公众号:扫描二维码,关注我们