
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to combine two arrays into an array of objects in JavaScript?
Let’s say the following are our two arrays −
var firstArray = ['John', 'David', 'Bob']; var secondArray = ['Mike','Sam','Carol'];
To combine two arrays into an array of objects, use map() from JavaScript.
Example
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);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo190.js.
Output
This will produce the following output −
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' ] ]
- Related Articles
- Combine array of objects in JavaScript
- JavaScript Converting array of objects into object of arrays
- JavaScript: create an array of JSON objects from linking two arrays
- How to combine 2 arrays into 1 object in JavaScript
- Combine two different arrays in JavaScript
- JavaScript: Combine highest key values of multiple arrays into a single array
- Convert array of objects to an object of arrays in JavaScript
- Array of objects to array of arrays in JavaScript
- How to add two arrays into a new array in JavaScript?
- Splitting an object into an array of objects in JavaScript
- Converting array of arrays into an object in JavaScript
- Combine unique items of an array of arrays while summing values - JavaScript
- How to Create an Array using Intersection of two Arrays in JavaScript?
- Convert an array of objects into plain object in JavaScript
- Flat a JavaScript array of objects into an object

Advertisements