xxxxxxxxxx
$scope.indexOfField = function(fieldId) {
var fieldData = $scope.model.fieldData,
i = 0, ii = $scope.model.fieldData.length;
for(i; i < ii; i++) if(fieldData[i].Id === fieldId) break;
// use i
}
xxxxxxxxxx
var list = ["apple","banana","orange"]
var index_of_apple = list.indexOf("apple") // 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
// 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);
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
fruits.push('Mango')
// ["Strawberry", "Banana", "Mango"]
let pos = fruits.indexOf('Banana')
// 1
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 : )