Answers for "array indexof find"

9

javascript indexOf object value in array

// Get index of object with specific value in array
const needle = 3; // needle
const haystack = [{ id: 1 }, { id: 2 }, { id: 3 }]; // haystack
const index = haystack.findIndex(item => item.id === needle);
Posted by: Guest on September-23-2020
0

javascrpt find index

const numbers = [2, 4, 5, 3, 8, 9, 11, 33, 44];
const findIndex = numbers.findIndex((number) => number == 5);
console.log(findIndex)
//Expected output: 2
Posted by: Guest on September-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language