1// Get index of object with specific value in array
2const needle = 3;
3const haystack = [{ id: 1 }, { id: 2 }, { id: 3 }];
4const index = haystack.findIndex(item => item.id === needle);
1var list = ["apple","banana","orange"]
2
3var index_of_apple = list.indexOf("apple") // 0
1const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
2
3beasts.indexOf('bison'); //ouput: 1
4
5// start from index 2
6beasts.indexOf('bison', 2); //output: 4
7
8beasts.indexOf('giraffe'); //output: -1
1var fruits = ["Banana", "Orange", "Apple", "Mango"];
2return fruits.indexOf("Apple"); // Returns 2