javascript find first item in array code example
Example 1: get first 10 items of array javascript
const list = ['apple', 'banana', 'orange', 'strawberry']
const size = 3
const items = list.slice(0, size)
Example 2: javascript array.find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 3: js array find
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
ages.find(checkAdult);
Example 4: find in js
The first element that will be found by that function
const f = array1.find(e => e > 10);
Example 5: javascript get first element of array
let mylist = ['one','two','three','last']
mylist[0],mylist[1],mylist[2],mylist[3]