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

get index of item array

const array = ['a', 'b', 'c']
array.indexOf('a')
 > 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

get item in array from index

var valueAtIndex1 = myValues[1];
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 :: Uncaught (in promise) DOMException: Failed to load because no supported source was found. 
Javascript :: clear input field data in jquery 
Javascript :: open another page js 
Javascript :: get date from datepicker 
Javascript :: nestjs set swagger api keys 
Javascript :: dynamic array in javascript 
Javascript :: agregar atributo con id jquery 
Javascript :: angular build deploy url 
Javascript :: Get specific route vuejs 
Javascript :: fizz buzz program in javascript 
Javascript :: to find keys in an object 
Javascript :: get year from date in mongodb 
Javascript :: formik seterrors 
Javascript :: js clearect 
Javascript :: babel debugging 
Javascript :: vue js app component 
Javascript :: react router dom props.history is undefined 
Javascript :: javascript map array 
Javascript :: react native debugger 
Javascript :: javascript caeser cipher 
Javascript :: array values js 
Javascript :: modern javascript for loop syntax 
Javascript :: expo modal 
Javascript :: google geocode nodejs 
Javascript :: javascript screenshot 
Javascript :: combine the values of 2 arrays in key = value jquery 
Javascript :: remove javascript 
Javascript :: entypo icons react native 
Javascript :: map keys to list node js 
Javascript :: null data type in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =