Notice
Recent Posts
Recent Comments
Link
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

개발일지

[JS] Array.prototype.map() 본문

Aura LWC JavaScript

[JS] Array.prototype.map()

청일쓰 2021. 7. 9. 15:27

map()메서드는 배열 내의 모든 요소 각각에 대하여 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환합니다.

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

매개변수

callback : 새로운 배열 요소를 생성하는 함수, 아래와 같이 3가지 인수를 가짐

-currentValue : 처리할 현재 요소

-index : 처리할 현재 요소의 인덱스

-array : msp()을 호출할 배열(List)

thisArg : callback을 실행할 때 this로 사용되는 값

 

반환 값

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

 

Ex :

const array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]

 var lists = [];
        component.get('v.lstSelectedRecords').map(x => lists.push(x.Id));
        console.log(lists);
        component.set('v.selectedRows',lists);

PriceBook 커스텀 .js중 검색기능의 검색결과의 선택한 레코드 아이디값만 넣은 화면 

 

 component.get('v.lstSelectedRecords')가 검색결과에서 레코드 선택한 변수