How to get the index of substring in array of strings in TypeScript

1 Answer

0 votes
const array = ['c++', 'javaScript', 'c', 'java 9', 'TYPEscript'];
const substring = 'script';
  
const index = array.findIndex(element => {
    if (element.includes(substring)) {
        return true;
    }
    return false;
});
  
console.log(index); 
  
  
  
  
  
/*
run:
  
4
  
*/

 



answered Feb 5, 2022 by avibootz
...