javascriptで配列の中のオブジェクトを探す方法

備忘録に書き留めておきます。

find(一つ)

const students = [  
    { name: 'bruno', age: '21' },  
    { name: 'michael', age: '25' },  
    { name: 'john', age: '30' },  
    { name: 'ann', age: '23' },  
]  

const target = students.find(student => student.name === 'bruno')  

console.log(target) // { bruno: '東京', age: '21' }  

filter(複数)

const students = [  
    { name: 'bruno', age: '21', class: 'B' },  
    { name: 'michael', age: '25', class: 'A' },  
    { name: 'john', age: '30', class: 'A' },  
    { name: 'ann', age: '23', class: 'B' },  
]  

const targetList = students.filter(student => student.class === 'B')  

console.log(targetList)  
// [  
//  { name: 'bruno', age: '21', class: 'B' },  
//  { name: 'ann', age: '23', class: 'B' },  
// ]