[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false
[1, 2, NaN].includes(NaN); // true
没有该方法之前,我们通常使用数组的indexOf方法,检查是否包含某个值。
if (arr.indexOf(el) !== -1) {
// ...
}
若是 后台返回 数组的形式
此处使用的是angular的写入
const arr = data.operationHistoryInfoList;
const sameTimeArr = [];
arr.forEarch(v=>{
if(!sameTimeArr.includes(v.operTime)){
sameTimeArr.push(v.operTime)
}
})
const newArr =[];
sameTimeArr.forEarch(item =>{
const sameArr = arr.filter(v=>item === v.operTime){
newArr.push({
operTime:item,
operTimeSameArr:sameArr
})
}
})