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

1 Answer

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

 



answered May 8, 2022 by avibootz
...