JavaScript TIP: Convert object to array
Explanation
Object.keys(obj)
: This method returns an array of a given object’s own enumerable property names.map((key) => obj[key])
: This method creates a new array populated with the results of calling a provided function on every element in the calling array.
Usage
To convert an object to an array, use the following code:
const obj = { 0: 'Frontend', 1: 'Snips' };
const arr = Object.keys(obj).map((key) => obj[key]);
console.log(arr);