DAY 24
0
Modern Web

## filter()

``````const numarr = [16, 7, 41, 43, 75, 91, 28, 39, 85, 14, 3, 43];
numarr.filter(a => a != 43);
// [16, 7, 41, 75, 91, 28, 39, 85, 14, 3]
numarr.filter(a => a < 43)
// [16, 7, 41, 28, 39, 14, 3]
``````

## every()

``````const numarr1 = [16, 7, 41, 43, 75, 91, 28, 39, 85, 14, 3, 43];
numarr1.every((b) => b < 2); // false
numarr1.every((b) => b > 2); // true
``````

## some()

``````const numarr2 = [16, 7, 41, 43, 75, 91, 28, 39, 85, 14, 3, 43];
numarr2.some((b) => b > 100); // false，全部都不大於 100
numarr2.some((b) => b < 31); //  true，部分小於 31
``````

## includes()

``````const numarr3 = [62, 19, 24, 63, 35, 17];
numarr3.includes(63); // true
numarr3.includes(63, 5); // false，從索引值 5 開始判斷
``````

## Array.isArray()

``````const x = { name: "Rex", age: 25 };
const y = 5566;
const z = ["Rex", 25, 55, 66];
Array.isArray(x); // false，是 object
Array.isArray(y); // false，是 number
Array.isArray(z); // true
``````

## 參考資料

### 1 則留言

0
Chiahsuan
iT邦新手 4 級 ‧ 2021-10-09 20:32:01

Rex iT邦新手 5 級 ‧ 2021-10-10 10:44:49 檢舉