js Intermediate
Convert JavaScript data structures
Open this example in our interactive code editor to experiment with it.
Try the EditorFrom object to array
const obj = {
a: 1,
b: 2,
c: 3
};
// All of the below are now an array,
// you can use all the array methods and properties,
// e.g. .reduce or .length
const keys = Object.keys(obj); // ['a', 'b', 'c']
const values = Object.values(obj); // [1, 2, 3]
const entries = Object.entries(obj); // [["a", 1], ["b", 2], ["c", 3]]
Summary
- Object.keys(), Object.values(), Object.entries().
- The above are ES8 (ECMAScript 2017) new methods which are extremely helpful when converting from an
Objectinto anArray.
Try this in our interactive code editor
Practice hands-on with our built-in code sandbox.
Open Code Editor
Adrian Bigaj
Creator of BigDevSoon
Full-stack developer and educator passionate about helping developers build real-world skills through hands-on projects. Creator of BigDevSoon, a vibe coding platform with 21 projects, 100 coding challenges, 40+ practice problems, and Merlin AI.
Related Pills
js Intermediate
JavaScript multiple condition checks
Checking multiple values in JavaScript often leads to redundant, boilerplate code - let's use .includes method to fix that.
js Intermediate
ECMAScript new features
Null coalescing operator, optional chaining, and Array.flat method are all amazing.
js Intermediate
Remove duplicates in JavaScript
Clones might take over the world, we need to learn how to remove duplicates from an array.