js find index in array by value code example
Example 1: findindex js
// findIndex(callback fn)
// .... return index (when condition meets)
// .... return -1 (if condition not meets)
const array = [5, 12, 8, 130, 44];
/// it returns the index of number which satisfy the condition true
const index = array.findIndex((item)=> item>10); //1
/// now we can check what element at that index...
console.log(array[index]); // array[1]
Example 2: index of value in array
// for dictionary case use findIndex
var imageList = [
{value: 100},
{value: 200},
{value: 300},
{value: 400},
{value: 500}
];
var index = imageList.findIndex(img => img.value === 200);
Example 3: .findIndex(
array.findIndex(call back function)
//index of ............
//first