javascript es6 check if index exists

Solutions on MaxInterview for javascript es6 check if index exists by the best coders in the world

showing results for - "javascript es6 check if index exists"
Alessio
29 Apr 2016
1const currentData = ['a', undefined], index = 1;
2
3if (index in currentData) {
4  console.info('exists');
5}
6// ...vs...
7if (typeof currentData[index] !== 'undefined') {
8  console.info('exists');
9} else {
10  console.info('does not exist'); // incorrect!
11}
similar questions
queries leading to this page
javascript es6 check if index exists