तत्वों को सेव करने के लिए 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 ] ]