js判断任意数值接近数组中的某个值
作者:互联网
可以是数组,也可以是数组对象,看需求定义
let val = '' for (let i = 0; i < this.allData.length; i++) { if (this.days >= this.allData[i].num) { val = i break } }
如果数据不规则,则先将数组进行排序
let allData= [ {name:'a',num:14}, {name:'b',num:5}, {name:'c',num:29}, {name:'d',num:33}, {name:'e',num:9}, ] console.log(allData); let allData1 = allData.sort(function(a,b) { return a.num - b.num }) console.log(allData1);
标签:console,name,数值,js,num,let,数组,allData 来源: https://www.cnblogs.com/rouyhx/p/15427774.html