Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

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);
Comment

js find index in list

let myList = ['foo', 'bar', 'qux'];

myList.indexOf('bar');	// 1
Comment

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
Comment

find index in array javascript

// 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)
Comment

js get index of item in array

array.indexOf("item");
Comment

Find the index of an item in the Array

fruits.push('Mango')
// ["Strawberry", "Banana", "Mango"]

let pos = fruits.indexOf('Banana')
// 1
Comment

javascript find index

const index = array.findIndex((param)=> param.name == "jimmy")
/* param will iterate on every value of the array looking for 
that one element that fits the criteria that is indicated in arrow function 
besides it */
Comment

Find Index in Array

$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
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to delete a variable in js 
Javascript :: update formgroup value angular 
Javascript :: You need to authorize this machine using `npm adduser` 
Javascript :: js date format mm/dd/yyyy 
Javascript :: javascript filter unique 
Javascript :: jquery serialize form data to object 
Javascript :: javascript loop over object entries 
Javascript :: express get client ip 
Javascript :: get the integer after decimal in javascript 
Javascript :: adding firebase to angular 
Javascript :: sort from the key value js 
Javascript :: hide and show modal in jquery 
Javascript :: javascript remove empty object items 
Javascript :: js window active 
Javascript :: jquery keep scroll position 
Javascript :: join text in js 
Javascript :: test undefined js 
Javascript :: apk react native 
Javascript :: Deleting all white spaces in a string 
Javascript :: Finding HTML Element by Id 
Javascript :: javascript date get nearest 15 minutes 
Javascript :: onclick open link js 
Javascript :: how to get json data from json file in node js 
Javascript :: update node mac to specific version 
Javascript :: javascript add function to onchange event 
Javascript :: react firebase hooks 
Javascript :: react detect enter key 
Javascript :: get ip address js 
Javascript :: if input value is null do something 
Javascript :: alert with sound javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =