練習運用 Array 的各種函式
目標
- 共提供二組資料- people: [{ name: ‘Wes’, year: 1988 },…]
- comments :[{ text: ‘Love this!’, id: 523423 },…]
 
- 根據不同需求條件篩選出正確的資料
練習題目
people 的資料:
- 在people資料中,是否有19歲以上的人
- 在people資料中,是否每個人都19歲以上
comments 的資料:
- 在comments資料中,找到id是 823423 的資料
- 在comments資料中,找到id是 823423 的資料索引值, 並透過索引值刪除這筆資料
成品
people 題目
| 1 | const people = [ | 
Q:在people資料中,是否有19歲以上的人
A:透過 some() 逐筆判斷,只要其中一筆有符合,就回傳 true
| 1 | // Some and Every Checks | 
Q:在在people資料中,是否每個人都19歲以上
A:透過 every() 逐筆判斷,只要其中一筆不符合,就回傳 false
| 1 | // Array.prototype.every() // is everyone 19 or older? | 
comments 題目
| 1 | const comments = [ | 
Q:在comments資料中,找到id是 823423 的資料
A:透過 find() 逐筆判斷,回傳 第一個符合條件的值,若都無符合,則回傳 undefined
| 1 | // Array.prototype.find() | 
Q:在comments資料中,找到id是 823423 的資料索引值, 並透過索引值刪除這筆資料
A:
- 透過 findIndex()逐筆判斷,回傳 第一個符合條件的索引值,若都無符合,則回傳-1
- 將取得的索引值,透過 slice()和Spread syntax(展開語法)的搭配使用,產出一新陣列
| 1 | // Array.prototype.findIndex() | 
