Array.prototype.map()

poburi FE·2020년 3월 8일
0

js

목록 보기
3/8
post-thumbnail

배열내의 모든 요소 각각 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환.

arr.map(callback(currentValue[, index[, array]])[, thisArg])

매개변수

  • 콜백: 새로운 배열 요소를 생성하는 함수. 다음 세 가지 인수를 가집니다.

    	* currentValue: 처리할 현재 요소.
    
    	* index(옵션): 처리할 현재 요소의 인덱스.
    
    	* array(옵션): map()을 호출한 배열.
  • thisArg(옵션): 콜백을 사용할 때 this로 사용되는 값.

반환값

배열의 각 요소에 대해 실행한 callback의 결과를 모은 새로운 배열.


var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);

결과값:
numbers = [1, 4, 9];
roots = [1, 2, 3];

profile
FE 개발자 poburi

0개의 댓글