functions to perform on array of objects in javascript code example

Example 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"},
    ...
];

Example 2: js array

var colors = [ "red", "orange", "yellow", "green", "blue" ]; //Array

console.log(colors); //Should give the whole array
console.log(colors[0]); //should say "red"
console.log(colors[1]); //should say "orange"
console.log(colors[4]); //should say "blue"

colors[4] = "dark blue" //changes "blue" value to "dark blue"
console.log(colors[4]); //should say "dark blue"
//I hope this helped :)