Categories
JavaScript Answers

How to check in JavaScript if a value exists at a certain array index?

Spread the love

To check in JavaScript if a value exists at a certain array index, we use check if the array item at the index is undefined or not.

For instance, we write

if (arrayName[index]) {
  //...
}

to get the item in arrayName at index.

If it’s not undefined, then the value exists.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.