50% off all plans with SPRING50
js Intermediate

Convert JavaScript data structures

Convert JavaScript data structures
Photo by Kelvin Ang on Unsplash
Object to Array Demo
Interactive editor — edit code and see live results Open in Editor

From 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

Try this in our interactive code editor

Practice hands-on with our built-in code sandbox.

Open Code Editor
Adrian Bigaj
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.