find index array js code example
Example 1: how to find the index of a value in an array in javascript
var list = ["apple","banana","orange"]
var index_of_apple = list.indexOf("apple")
Example 2: javascript findindex
const array1 = [5, 12, 8, 130, 44];
const search = element => element > 13;
console.log(array1.findIndex(search));
const array2 = [
{ id: 1, dev: false },
{ id: 2, dev: false },
{ id: 3, dev: true }
];
const search = obj => obj.dev === true;
console.log(array2.findIndex(search));
Example 3: js find index in list
let myList = ['foo', 'bar', 'qux'];
myList.indexOf('bar');
Example 4: get array by array of indices js
var resultArr = indexArr.map(i => fruitier[i])
Example 5: access index of array javascript
let first = fruits[0]
let last = fruits[fruits.length - 1]