Converting an Object to an Array
Suppose We have an Object. The object is given below:
The object name is 'avengers'. Now we are given a task to create an array from it. We can create three different arrays from it.
We can create different arrays from one object. Here are examples:
By using the 'Object.keys()' - method, we can create an array by only using keys of the object. We just simply need to pass the object name in the bracket. This will create an array with the keys of the object.
By using the 'Object.values()' - method, we can create an array by only using values of the keys of the object. We just simply need to pass the object name in the bracket. This will create an array with the values of the keys of the object.
Now Suppose we want to create an array from this object consisting of enumerable property [key, value] pair. This can also be done by using a simple method.
'Object.entries()' - method are used to create an array with [key, value] pair.
This is a simple blog about how we can create 3 different types of array from an single object.