How to get the index of substring in array of strings in Node.js

1 Answer

0 votes
const array = ['c++', 'Node.js', 'c', 'java 9', 'php', 'node.js'];
const substring = 'node';
  
const index = array.findIndex(element => {
    if (element.includes(substring)) {
        return true;
    }
});
  
console.log(index); 
  
  
  
  
  
/*
run:
  
5
  
*/

 



answered Feb 5, 2022 by avibootz

Related questions

...