Math.floor(Math.random() * array.length),splice
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的更多相关文章
- Math.floor(Math.random()*3+1)
Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and ret ...
- Number(),parseInt(),parseFloat(),Math.round(),Math.floor(),Math.ceil()对比横评
首先,这些处理方法可分为三类. 1,只用来处理数字取整问题的:Math.round(),Math.floor(),Math.ceil(): 2,专门用于把字符串转化成数值:parseInt(),par ...
- 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 ...
- 如何在一个页面后面随机跳转到多个链接地址Math.floor()和Math.random()
点击一个标签随机跳转到多个链接地址,主要运用javascript中的Math.floor()和Math.random()方法 floor(x) 方法是向下去整数 参数为任意数值或表达式. floor( ...
- 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 ...
- 转载:使用Math.floor和Math.random取随机整数
Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and ret ...
- 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() 语法 ...
- Python标准库12 数学与随机数 (math包,random包)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们已经在Python运算中看到Python最基本的数学运算功能.此外,math包 ...
- Java Math floor round ceil 函数
public final class Math extends Object public static double floor(double a) public static long round ...
随机推荐
- centos8平台给sudo配置日志
一,sudo日志的用途: 我们可以记录下来用户账号在哪个时间进行过sudo 这样不需要再从secure日志中查找用户的sudo记录 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://w ...
- Centos6.X 手动升级gcc
操作环境 CentOS6.5 64bit,gcc原版本为4.4.7,不能支持C++11的特性,所以需要升级 [root@zengxj ~]# wget http://ftp.gnu.org/gnu/g ...
- HTML语义化罗嗦罗嗦
CSS还未诞生之前,为了实现一些样式效果.设计师必须使用一些物理标签,例如font.b等.这样会造成页面中充满了为实现各种样式的标签,特别是使用table标签来实现一些特殊的布局,俗称为"标 ...
- 深入理解Java的抽象类和接口
对于面向对象来说,抽象是其重要特征之一.对于之中的抽象类和接口,两者有很多相似的地方,又有两者之间区别的地方. 用几个简单的例子让你快速的理解两者之间的概念和区别 鸣谢 一.抽象类 在了解抽象类之前, ...
- Html+Ajax+Webservice 实现文件跨域上传
1. 界面HTML <p >上传文件: <input id="zfiles" type="file" name="file" ...
- Spring Boot注解与资源文件配置
date: 2018-11-18 16:57:17 updated: 2018-11-18 16:57:17 1.不需要多余的配置文件信息 application.properties mybatis ...
- 案例>>>用绝对值的方法打印出菱形
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = ...
- GPRS DTU工作的原理与应用场景
GPRS DTU是属于物联网无线数据终端设备的中一种,它主要是利用公用运营商的GPRS网络(又称G网)来为用户提供无线长距离数据传输的功能.一般都是采用的高性能工业级8/16/32位通信处理器和工业级 ...
- 部署LNMP环境
1.安装nginx yum -y install gcc pcre-devel openssl-devel tar xf nginx-1.16.1.tar.gz cd nginx-1.16.1/ ./ ...
- Java学习的第十七天
1.静态变量 静态方法 静态代码块 2.今天没问题 3.明天学习abstract和综合实例