자바스크립트 map()

Jmnote (토론 | 기여)님의 2022년 5월 1일 (일) 21:11 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

JavaScript map()
const a = [1, 2, 3, 4];
const result = a.map(x => x * 2);
console.log(result); // [2, 4, 6, 8]
members = [
  { id: 102, name: 'Ashley Allen', address: 'Seoul' },
  { id: 202, name: 'Peter Parker', address: 'New York' },
  { id: 104, name: 'John Smith', address: 'Tokyo' }
];
console.log(members.map(x => x.address)); // [ 'Seoul', 'New York', 'Tokyo' ]

2 2차원 배열[ | ]

const arr = [[2, 3], [1, 6, 7], [5, 4, 3, 2]];
const result = arr.map(a => a.map(b => b*2));
console.log(result);

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}