Answers for "index of item in array javascript"

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
4

javascript get index of object in array

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

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") // 0
Posted by: Guest on February-01-2020
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);
Posted by: Guest on June-27-2020
5

get index of element in array js

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];

beasts.indexOf('bison'); //ouput: 1

// start from index 2
beasts.indexOf('bison', 2); //output: 4

beasts.indexOf('giraffe'); //output: -1
Posted by: Guest on October-28-2020
7

js get index of item in array

array.indexOf("item");
Posted by: Guest on May-13-2020

Code answers related to "index of item in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language