1// for dictionary case use findIndex
2var imageList = [
3 {value: 100},
4 {value: 200},
5 {value: 300},
6 {value: 400},
7 {value: 500}
8];
9var index = imageList.findIndex(img => img.value === 200);
1const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
2
3console.log(beasts.indexOf('bison'));
4// expected output: 1
5
6// start from index 2
7console.log(beasts.indexOf('bison', 2));
8// expected output: 4
9
10console.log(beasts.indexOf('giraffe'));
11// expected output: -1
1var fruits = ["Banana", "Orange", "Apple", "Mango"];
2return fruits.indexOf("Apple"); // Returns 2
1var array = [2, 9, 9];
2array.indexOf(2); // 0
3array.indexOf(7); // -1
4array.indexOf(9, 2); // 2
5array.indexOf(2, -1); // -1
6array.indexOf(2, -3); // 0
1let first = fruits[0]
2// Apple
3
4let last = fruits[fruits.length - 1]
5// Banana
6