Answers for "create objects from two arrays javascript"

15

javascript difference between two arrays

let difference = arr1.filter(x => !arr2.includes(x));
Posted by: Guest on April-03-2020
1

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"},
    ...
];
Posted by: Guest on July-03-2020

Code answers related to "create objects from two arrays javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language