js find first code example

Example 1: javascript array.find

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12

Example 2: find a single element in array of objects javascript

myArray.find(x => x.id === '45').foo;

Example 3: js get first item from array

var colors = ["red", "green", "blue"];
var red=colors.shift();
//colors is now ["green","blue"];

Example 4: javascript find first element of array

let array = ["a", "b", "c", "d", "e"];

// Both first1 and first2 have the same value.
let [first1] = array;
let first2 = array[0];