Answers for "javascript es6 check if index exists"

0

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!
}
Posted by: Guest on September-24-2021

Code answers related to "javascript es6 check if index exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language