1、Math.floor(Math.random() * array.length)

返回长度内的索引

eg:

changeLimit () {
  function getArrayItems(arr, num) {
    const temp_array = [];
    for(let index in arr) {
      temp_array.push(arr[index]);
    }
    const return_array = [];
    for (let i = 0; i<num; i++) {
      if(temp_array.length>0) {
        const arrIndex = Math.floor(Math.random()*temp_array.length);
        return_array[i] = temp_array[arrIndex];
        temp_array.splice(arrIndex, 1);
      } else {
        break;
      }
    }
    return return_array;
  }
  this.randomMovieList = getArrayItems(this.movieList, 5);
}

2、splice

temp_array.splice(arrIndex, 1),

删除temp_array中下标为arrIndex的那个元素

Math.floor(Math.random() * array.length),splice的更多相关文章

  1. Math.floor(Math.random()*3+1)

    Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and ret ...

  2. Number(),parseInt(),parseFloat(),Math.round(),Math.floor(),Math.ceil()对比横评

    首先,这些处理方法可分为三类. 1,只用来处理数字取整问题的:Math.round(),Math.floor(),Math.ceil(): 2,专门用于把字符串转化成数值:parseInt(),par ...

  3. js 中的 Math.ceil() Math.floor Math.round()

    alert(Math.ceil(25.9)); alert(Math.ceil(25.5)); alert(Math.ceil(25.1)); alert(Math.round(25.9)); ale ...

  4. 如何在一个页面后面随机跳转到多个链接地址Math.floor()和Math.random()

    点击一个标签随机跳转到多个链接地址,主要运用javascript中的Math.floor()和Math.random()方法 floor(x) 方法是向下去整数 参数为任意数值或表达式. floor( ...

  5. Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?

    Math.round(x) 四舍五入 加上0.5向下取整 Math.round(1.5) 2 Math.round(-11.5) -11 Math.round(-11.2) -10 Math.ceil ...

  6. 转载:使用Math.floor和Math.random取随机整数

    Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and ret ...

  7. JavaScript中的内置对象-8--3.Math-Math对象的方法-min()- max()- ceil() - floor()- round()- abs(); Math对象的random()方法;

    JavaScript内置对象-3.Math(数值) 学习目标 1.掌握Math对象的方法: min() max() ceil() floor() round() abs() Math.min() 语法 ...

  8. Python标准库12 数学与随机数 (math包,random包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们已经在Python运算中看到Python最基本的数学运算功能.此外,math包 ...

  9. Java Math floor round ceil 函数

    public final class Math extends Object public static double floor(double a) public static long round ...

随机推荐

  1. Excel中外部数据链接无法删除的解决方法【转】

    [摘要] 当Excel中公式引用了外部数据,每次打开时,总是自动弹出自动更新链接的对话框.如何找到这些链接?有没有办法实现断开原有链接,而保持数值不变? 有客户反应,当Excel无法链接到外部数据后, ...

  2. MySQL备份和恢复[3]-mysqldump备份工具

    mysqldump 概述 逻辑备份工具: mysqldump, mydumper, phpMyAdmin Schema和数据存储在一起.巨大的SQL语句.单个巨大的备份文件 mysqldump:是My ...

  3. APP打开(一)—以亲身经历谈APP注册登录

    如果不是自己接手过这样的产品,我可能也很难相信,会有公司能够做出十四个注册页面的APP,将选站点.输账号.输密码.用户协议.用户权限等全部拆解成一个一个单独的页面来做,用户在注册的时候仿佛在攀登一座云 ...

  4. 抽空学学KVM(七):虚拟机快照和克隆

    前几天学写了KVM中qume-info命令的使用,今天学学在虚拟化里面用处广泛的快照和克隆功能,snapshot和virt-clone.对于snapshot命令的使用其实很简单.进入virsh界面以后 ...

  5. was 发布版本的步骤:

    was 发布版本的步骤:实际使用:1.备份应用 (备份应用下的war包,tar -czvf app.20200418.tar.gz app.war)2.停服务(was 控制台停,方便)3.替换该版本文 ...

  6. RocketMQ 4.7.1 环境搭建、集群、MQ整合SpringBoot

    导读 之前学过ActiveMQ但是并发量不是很大点我直达,所以又学阿里开源的RocketMQ,据说队列可以堆积亿级别.下面是网上找的消息队列对比图,仅供参考 部署 官网 点我直达 前置条件 推荐使用6 ...

  7. okhttp的Post方式

    发送post请求 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bun ...

  8. Distcp 跨集群同步

    date: 2020-10-09 17:45:00 updated: 2020-10-10 17:45:00 Distcp 跨集群同步 1. 使用方法及原理 hadoop distcp srcPath ...

  9. Stimulsoft报表工具中属性表达式设置属性表达式

    Stimulsoft仪表工具实现所需的数据可视化和自己的信息图表.该产品能够应用必要的过滤器和排序,汇总数据,执行任何复杂度的计算.该产品的优势在于其多功能性-能够为您的业务,财务,销售,行业等任何领 ...

  10. 计算机CPU是怎么认识代码的?

    先说一下半导体,啥叫半导体?就是介于导体和绝缘体中间的一种东西,比如二极管.   电流可以从A端流向C端,但反过来则不行.你可以把它理解成一种防止电流逆流的东西. 当C端10V,A端0V,二极管可以视 ...