개요
- 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차원 배열
const arr = [[2, 3], [1, 6, 7], [5, 4, 3, 2]];
const result = arr.map(a => a.map(b => b*2));
console.log(result);
같이 보기
- 자바스크립트 forEach()
- 자바스크립트 from()
- 자바스크립트 filter()
- 자바스크립트 reduce()
- 자바스크립트 pluck()
- JavaScript 딕셔너리 리스트 컬럼 추출하여 리스트 만들기