Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript es6 check if index exists

const currentData = ['a', undefined], index = 1;

if (index in currentData) {
  console.info('exists');
}
// ...vs...
if (typeof currentData[index] !== 'undefined') {
  console.info('exists');
} else {
  console.info('does not exist'); // incorrect!
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #check #index #exists
ADD COMMENT
Topic
Name
3+5 =