तत्वों को सहेजने के लिए मानचित्र () फ़ंक्शन का सही ढंग से उपयोग करें।
उदाहरण
निम्नलिखित कोड है -
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 ] ]