How to check if specific index exists in array with JavaScript

1 Answer

0 votes
const array = ["javascript", "php", "ruby", "c++"];

const index = 5;

if (array[index] !== undefined) {
  	console.log("index: " + index + " exists"); 
} else {
	console.log("index: " + index + " not exists"); 
}
  
   
   
/*
run:
         
"index: 5 not exists"
       
*/

 



answered Jul 10, 2022 by avibootz
...