fatherdata.filter((item, key) => key < 5);截取fatherdata的前5个数据。
- 根据对象内某字段进行排序 / / ** 运用方式 ** obj.sort(compare(property)); */ const compare = property => { return (a, b) => { var value1 = a[property]; var value2 = b[property]; return value2 - value1; } }
/* 数组排序 / / ** 运用方式 ** obj.sort(sortNumber); */ const sortNumber = (a, b) => { return a - b; }
给数组中的每隔对象添加一个属性: let OrderList1=OrderList2.map(item=>{ return {...item,allorderstate:''} }); .van-hairline--top-bottom::after, .van-hairline-unset--top-bottom::after { border-width: 0; }
5.循环对象并且修改原对象 for(let k in zongheList){ zongheList[k].updatetime=zongheList[k].updatetime.replace(/T/,' '); console.log(zongheList[k].updatetime);} console.log(zongheList); 6.给对象的时间排序 let newArray=zongheList newArray.sort(function(a,b){ return Date.parse(a.updatetime)-Date.parse(b.updatetime); }); console.log(newArray); 7.js 使用ES6 实现从json中取值并返回新的数组或者字符串 let result = data.map(data => n.name).join();//'张三,李四,王五'
let results = data.map(data => n.name);//['张三','李四','王五']