How to check if specific index exists in array with TypeScript

1 Answer

0 votes
const array = ["typescript", "php", "ruby", "c++"];
 
const index = 4;
 
if (array[index] !== undefined) {
    console.log("index: " + index + " exists"); 
} else {
    console.log("index: " + index + " not exists"); 
}
   
    
    
/*
run:
          
"index: 4 not exists" 
        
*/

 



answered Jul 10, 2022 by avibootz

Related questions

1 answer 163 views
1 answer 138 views
2 answers 165 views
1 answer 135 views
1 answer 185 views
...