Js數組includes()使用方式 該方法返回一個布爾值,表示某個數組是否包含給定的值


[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 

   })

 }
})        

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM