javascript create array of objects from multiple arrays
var ids = [1,2,3]; //Hundreds of elements here
var names = ["john","doe","foo"]; //Hundreds of elements here
var countries = ["AU","USA","USA"]; //Hundreds of elements here
// Create the object array
var items = ids.map((id, index) => {
return {
id: id,
name: names[index],
country: countries[index]
}
});
// Result
var items = [
{id: 1, name: "john", country: "AU"},
{id: 2, name: "doe", country: "USA"},
...
];
Also in JavaScript:
- for javascript
- close browser tab javascript
- string.contains javascript
- codemirror get value
- js wait for time
- print pdf javascript
- moment add 30 days
- jsx full form
- fs.readfile
- javascript multiline string
- statusbar reactnati
- nested array loop in javascript
- javacript getHTTPURL
- javascript on hover
- js replace quotes
- update head tag metadata vue
- nodejs fs delete non empty directory
- jquery sort select options by text
- regular expression flags
- comment out in javascript
- javascript detect click outside element
- arrays javascript
- json vs gson
- tolowercase