How to convert a JavaScript object to array?

Sometimes, we want to convert a JavaScript object to array.

In this article, we’ll look at how to convert a JavaScript object to array.

How to convert a JavaScript object to array?

To convert a JavaScript object to array, we can use the Object.values method to return the object property values in an array.

For instance, we write:

const o = {
  0: "a",
  1: 'b'
};
const a = Object.values(o);
console.log(a)

To call Object.values with o.

Then we see that a is ['a', 'b'] from the console log.

Conclusion

To convert a JavaScript object to array, we can use the Object.values method to return the object property values in an array.