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];
var names = ["john","doe","foo"];
var countries = ["AU","USA","USA"];
var items = ids.map((id, index) => {
return {
id: id,
name: names[index],
country: countries[index]
}
});
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" ];
console.log(colors);
console.log(colors[0]);
console.log(colors[1]);
console.log(colors[4]);
colors[4] = "dark blue"
console.log(colors[4]);