উপাদানগুলি সংরক্ষণ করতে মানচিত্র() ফাংশন সঠিকভাবে ব্যবহার করুন৷
উদাহরণ
নিম্নলিখিত কোড -
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 ] ]