您现在的位置是:网站首页>文章详情文章详情

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


很赞哦! ( 18)
    《Python实战进阶》
    None
    None
    夏至已深

站点信息

  • 建站时间:2019-5-24
  • 网站程序:like in love
  • 主题模板《今夕何夕》
  • 文章统计:104条
  • 文章评论:***条
  • 微信公众号:扫描二维码,关注我们
  • 个人微信公众号