Categories
JavaScript Answers

How to find the array index with a value with JavaScript?

Spread the love

To find the array index with a value with JavaScript, we use the indexOf method.

For instance, we write

const imageList = [100, 200, 300, 400, 500];
const index = imageList.indexOf(200);

to call imageList.indexOf with 200 to return the first index of 200 in the imageList array.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.