- find替換查找符合條件數據:返回符合條件的第一個數據
// find 返回第一個合適的就停止 // 在函數中如果找到符合條件的數組元素就進行return,並停止查找。 // 你可以拷貝下邊的代碼進行測試,就會知道find作用。 let a = data.find(item => item.age > 20) console.log(a); // forEach 無返回值:所以輸出undefined // map 有返回值:符合條件輸出item,不符合默認return;,輸出undefined let aa = data.map(item => { if(item.age > 20) { return item; } })
let bb = data.forEach(item => {
if(item.age > 20) {
return item;
}
})
let cc = data.filter(item => {
if(item.age > 20) {
return item;
}
})
let has = data.some(item => item.age > 30 )
let has2 = data.every(item => item.age > 10)

