Languages
[Edit]
EN

JavaScript - convert object to array

0 points
Created by:
Jun-L
963

In this article, we would like to show you how to convert object to array in JavaScript.

To convert an object to an array we can use one of the following methods:

  1. Object.keys() - converts object keys into an array,
  2. Object.values() - converts object values into an array,
  3. Object.entries() - converts enumerable string-keyed properties [key, value] pairs of an object into an array.

Note:

The Object.keys() method has been introduced in ES6, and the Object.values() and Object.entries() in ES8.

1. Convert object keys to array

Edit

In this example, we use Object.keys() method to convert keys of the object into array.

2. Convert object values to array

Edit

In this example, we use Object.values() method to convert values of the object into array.

 

3. Convert object entries (key-value pairs) to array

Edit

In this example, we use Object.entries() method to convert enumerable string-keyed properties [key, value] pairs of the object into array.

 

See also

Edit
  1. JavaScript - convert object to array of key-value pairs

References

Edit
  1. Object.keys() - JavaScript | MDN
  2. Object.values() - JavaScript | MDN
  3. Object.entries() - JavaScript | MDN

Alternative titles

  1. JavaScript - converting object with numeric keys into array
  2. JavaScript - convert Object to Array using ES6 features
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join