How to use some() Method In Javascript
The Javascript arr.some() method checks whether at least one of the elements of the array satisfies the condition checked by the argument method.
Example: In this example we have used some() Method
Javascript
let arrayObj = [{ prop_1: 'val' , prop_2: 'val_12' , prop_3: 'val_13' }, { prop_1: 'val' , prop_2: 'val_22' , prop_3: 'val_23' }]; let index; arrayObj.some((object, idx) => { if (object.prop_2 === 'val_12' ) { index = idx; return true ; } }); console.log(index); |
Output
0
JavaScript Get the index of an object by its property
Given an object, the task is to get the object’s index from the array of objects of the given property name and property value using JavaScript. we’re going to discuss a few techniques.
Below are the following approaches:
Table of Content
- Using Array map() Method
- Using for loop
- Using findIndex() Method
- Using some() Method
Contact Us