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 ...
随机推荐
- 第二十六章 ansible主要模块介绍
一.Ansible模块回顾 1.command模块 [root@m01 ~]# ansible web01 -m command -a 'free -m' 2.shell模块 #支持管道符这种特殊符号 ...
- JavaSE学习笔记02运算符、帮助文档生成与Scanner输入
1. 运算符 1. 算术运算符:+,-,*,/,%,++,-- //二元运算符 int a = 10; int b = 20; int c = 25; int d = 25; System.out.p ...
- python第一章:基础
1.数学操作符: 数学操作符与数学基本类似 最高级:** 第二级:*././/.% 第三级:+ .- 遵循从左到右的顺序 如果想改变优先级 可以使用括号,比如:(3+2)*(5-4)=5*1=5 2. ...
- python坐标获取经纬度或经纬度获取坐标免费模块--geopy
一.官方文档 https://github.com/geopy/geopy 二.模块安装 pip3 install geopy 三.简单实用 from geopy.geocoders import N ...
- LeakCanary检测(二)
在主方法主实现一个内存泄漏,检测到手机会发送通知,也可以用利用androidStudio自带的Profile检测内存泄漏 public class MainActivity extends AppCo ...
- Disruptor 使用简介
[开发总结]Disruptor 使用简介 在极客时间看到王宝令老师关于 Disruptor 的一篇文章,觉得很有意思.看完之后又在网上找到一些其他关于Disruptor 的资料看了一下. 现在写篇文章 ...
- 配置kuernetes集群pod拉取私有镜像仓库中的镜像
目录 1 背景说明 2 实现方法 3 具体实现 配置镜像仓库项目为公开类型(任何人可以访问) 配置docker-registry类型的secret(pod使用secret获取镜像认证) 通过账户名密码 ...
- 一文搞懂后台高性能服务器设计的常见套路, BAT 高频面试系列
微信搜索「编程指北」,关注这个写干货的程序员,回复「资源」,即可获取后台开发学习路线和书籍 先赞后看,养成习惯~ 前言 金九银十,又是一年校招季. 经历过,才深知不易.最近,和作为校招面试官的同事聊了 ...
- 想springboot启动完成后执行某个方法
如题,很多时候,我们都需要在springboot项目启动后初始化化一些自己的数据 原文地址:https://www.jianshu.com/p/f80f833ab8f6 实现方法有2个. 一.Appl ...
- rabbitmq集群搭建,镜像队列搭建
原文地址:https://www.jianshu.com/p/11963564dd3d 教你如何从0开始搭建rabbitmq集群 一.准备工作 1.三台centos虚拟机 2.三台虚拟机都安装了doc ...