Convert an object's values to an array
suggest changeGiven this object:
const obj = {
a: "hello",
b: "this is",
c: "javascript!",
};
You can convert its values to an array by doing:
const array = Object.keys(obj)
.map(function(key) {
return obj[key];
});
console.log(array); // ["hello", "this is", "javascript!"]
Object.values(obj) returns that same array. Both skip symbol keys. String-key order follows the usual own-property order.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents