मान लें कि निम्नलिखित हमारे दो सरणियाँ हैं -
var firstArray = ['John', 'David', 'Bob']; var secondArray = ['Mike','Sam','Carol'];
दो सरणियों को वस्तुओं की एक सरणी में संयोजित करने के लिए, जावास्क्रिप्ट से मानचित्र () का उपयोग करें।
उदाहरण
var firstArray = ['John', 'David', 'Bob'];
var secondArray = ['Mike','Sam','Carol'];
var arrayOfObject = firstArray.map(function (value, index){
return [value, secondArray[index]]
});
console.log("The First Array=");
console.log(firstArray);
console.log("The Second Array=");
console.log(secondArray);
console.log("The mix Of array object=");
console.log(arrayOfObject); उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्न कमांड का उपयोग करने की आवश्यकता है -
node fileName.js.
यहाँ, मेरी फ़ाइल का नाम है demo190.js.
आउटपुट
यह निम्नलिखित आउटपुट देगा -
PS C:\Users\Amit\javascript-code> node demo190.js The First Array= [ 'John', 'David', 'Bob' ] The Second Array= [ 'Mike', 'Sam', 'Carol' ] The mix Of array object= [ [ 'John', 'Mike' ], [ 'David', 'Sam' ], [ 'Bob', 'Carol' ] ]