过滤
let paid =res.data.data.filter(item =>item.status==1)paid.sort((a,b)=>{ //return( a[a] - b[a]) return( a.a- b.a) })
排序
let paid = [{a:1,name:你好},{a:0,name:你好}]
深拷贝
let cp = JSON.parse(JSON.stringify(obj));
结构赋值
let {aa, bb, dd, ee} = obj; let newObj = {aa, bb, dd, ee};
forEach
let arr = [1,2,3]; arr.forEach(i => console.log(i))
forMap
let arr = [1,2,3,4,5]; let res = arr.map(i => i * i);
截取
var str=location.href; var s=str.indexOf("?"); var t=str.substring(s+1) var a=t.lastIndexOf("#"); var stt=t.substring(0,a)
//以? 开始 #结束
数组求平均值
const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length; average(...[1, 2, 3]); // 2 average(1, 2, 3); // 2
标签:常用,nums,average,arr,paid,js,let,var From: https://www.cnblogs.com/7788mmhh/p/17213215.html