Categories
JavaScript Answers

How to iterate array keys in JavaScript?

Spread the love

To iterate array keys in JavaScript, we use the Object.keys method to get an array of string keys from the array.

For instance, we write

const array = [];
widthRange[46] = { sel: 46, min: 0, max: 52 };
widthRange[66] = { sel: 66, min: 52, max: 70 };
widthRange[90] = { sel: 90, min: 70, max: 94 };
const keys = Object.keys(array);

to call Object.keys with array to return an array of indexes of the array 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. Required fields are marked *