map() 함수를 올바르게 사용하여 요소를 저장하십시오.
예시
다음은 코드입니다 -
const addIndexValueToArrayElement = function (arrObject) {
const updatedArrayValue = [];
arrObject.forEach(function (ob) {
const mapValue = ob.map(function (value) {
return value + arrObject.indexOf(ob)
})
updatedArrayValue.push(mapValue)
})
return updatedArrayValue;
};
const output = addIndexValueToArrayElement([
[4, 5],
[7, 56],
[34, 78],
]);
console.log(output); 위의 프로그램을 실행하려면 아래 명령을 사용해야 합니다 -
node fileName.js.
여기에서 내 파일 이름은 demo323.js입니다.
출력
이것은 다음과 같은 출력을 생성합니다 -
PS C:\Users\Amit\javascript-code> node demo323.js [ [ 4, 5 ], [ 8, 57 ], [ 36, 80 ] ]