"자바스크립트 map()"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 14개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;JavaScript map()
;JavaScript map()


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


==2차원 배열==
{{참고|JavaScript 2차원 배열 원소 각각 2배로}}
<syntaxhighlight lang='javascript' run>
const arr = [[2, 3], [1, 6, 7], [5, 4, 3, 2]];
const result = arr.map(a => a.map(b => b*2));
console.log(result);
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[JavaScript filter()]]
* [[자바스크립트 forEach()]]
* [[자바스크립트 from()]]
* [[자바스크립트 filter()]]
* [[자바스크립트 reduce()]]
* [[자바스크립트 pluck()]]
* [[JavaScript 딕셔너리 리스트 컬럼 추출하여 리스트 만들기]]
* [[JavaScript 딕셔너리 리스트 컬럼 추출하여 리스트 만들기]]


20번째 줄: 35번째 줄:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map


[[분류: JavaScript]]
[[분류: JavaScript map()]]

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 }}