方法很多种,个人认为这种写法不需要脑子。
let arr=[];
while(arr.length<100){
let newval=Math.round((Math.random()*100).toFixed(2))//创建变量保存生成的随机数0-100
arr.indexOf(newval)==-1?arr.push(newval)&&console.log(‘添加成功’):console.log(‘添加失败,已存在该元素’)}
就这样完事,可以自行改造
方法很多种,个人认为这种写法不需要脑子。
let arr=[];
while(arr.length<100){
let newval=Math.round((Math.random()*100).toFixed(2))//创建变量保存生成的随机数0-100
arr.indexOf(newval)==-1?arr.push(newval)&&console.log(‘添加成功’):console.log(‘添加失败,已存在该元素’)}
就这样完事,可以自行改造