xxxxxxxxxx
const array = ['a', 'b', 'c']
array.indexOf('a')
> 0
xxxxxxxxxx
// find index of array in javascript
const number = [1,6,2,8,1,0,4,2,7,5,4,1];
const index = number.findIndex(item => item === 8);
console.log(index)
xxxxxxxxxx
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
xxxxxxxxxx
var fruits = ["Banana", "Orange", "Apple", "Mango"];
return fruits.indexOf("Apple"); // Returns 2
xxxxxxxxxx
fruits.push('Mango')
// ["Strawberry", "Banana", "Mango"]
let pos = fruits.indexOf('Banana')
// 1
xxxxxxxxxx
var elementPos = array.map(function(x) {return x.id; }).indexOf(idYourAreLookingFor);
var objectFound = array[elementPos];
xxxxxxxxxx
// If you want to find the index of item present in array then here is
// a method call indexOf with this method you can find index of item
// EXAMPLE ----
// Tip : 1
// Use const to define a Array because you know javascript stores
// refrence data types in heap // It's mean you can access the array
// Dynamically
const names = ["Fahad","Shaikh","Your_Name"]
// It'll log the result in the console
console.log(names.indexOf("Your_name")); // And you guess right it'll
// return ---> 2 because Your Name is present in names[2]
// And if you want to store the index in a variable you use syntax
// given below
// Tip : 2
// use camel case to define variable names and don't be afraid to give
// big name to variable
const indexOfYourName = list.indexOf("apple") // 0
// Enjoy Coding : )