음악, 삶, 개발

Array 의 map 본문

개발 Web/JS

Array 의 map

Lee_____ 2021. 3. 12. 03:47

< 참고 자료 : youtu.be/3CUjtKJ7PJg?t=1198 >

 

map 은 Array 에서 각 요소들을 다른 방식으로 매핑해주는것이다.

또는 각 요소들이 객체일 경우, 일부 property 만을 추출하는 새로운 array 로 만들때도 유용하다.

const people = [

    { name : 'kim',  age : 10 },
    { name : 'seo',  age : 64 },
    { name : 'choi', age : 55 },

]

const ages = people.map((p) => p.age)

console.log(ages) // [10, 64, 55]