개발일지
[JS] Array.prototype.map() 본문
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')가 검색결과에서 레코드 선택한 변수
'Aura LWC JavaScript' 카테고리의 다른 글
LWC Lightning-Input CSS 수정시 적용이 안될 때 Dom Control하기 (0) | 2025.02.12 |
---|---|
map을 활용해 배열 속 객체를 재구성하기 (1) | 2021.07.09 |