get the array node JS code example

Example 1: js get array item by property

const jsObjects = [
  {id: 1, displayName: "First"}, 
  {id: 2, displayName: "Second"}, 
  {id: 3, displayName: "Third"}, 
  {id: 4, displayName: "Fourth"}
]

// You can use the arrow function expression:
var result = jsObjects.find(obj => {
	// Returns the object where
	// the given property has some value 
  	return obj.id === 1
})

console.log(result)

// Output: {id: 1, displayName: "First"}

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 :)