How to get the index of the first match of a value in an array with TypeScript

2 Answers

0 votes
const arr: Array<string> = ['TypeScript', 'C++', 'Java', 'C', 'Python', "C#"]; 
 
console.log(arr.indexOf('C'));

console.log(arr.indexOf('NodeJS'));
  
  

  
/*
  
run:
  
3
-1

*/

 



answered Aug 13, 2022 by avibootz
0 votes
const arr: Array<number> = [4, 8, 3, 10, 5, 0, 9, 7, 2]; 

console.log(arr.indexOf(5));

console.log(arr.indexOf(14));
  
  

  
/*
  
run:
  
4
-1

*/
  

 



answered Aug 13, 2022 by avibootz
...