How to get the index of an object in array that matching a condition with JavaScript

1 Answer

0 votes
const arr = [{lang: 'javascript'}, {lang: 'typescript'}, {lang: 'nodejs'}];
 
const index = arr.findIndex(element => {
    if (element.lang === 'javascript') {
            return true;
    }
 
    return false;
});
 
console.log(index);
 
   
   
   
/*
run:
   
0
   
*/

 



answered May 8, 2022 by avibootz
...