JavaScript: Object to Array

By Xah Lee. Date: . Last updated: .

How to convert a object to array?

Use the following methods. Which one to use depends on if you want enumerable keys only, and or including symbol keys.

Properties to Array
syntaxmeaningproto chainenumerable onlyinclude symbol keyinclude string key
Object.keys(o) 〔►see JavaScript: Object.keysnoyesnoyes
Object. getOwnPropertyNames(o) 〔►see JavaScript: Object.getOwnPropertyNamesnononoyes
Object. getOwnPropertySymbols(o) (ES2015) 〔►see JavaScript: Object.getOwnPropertySymbolsnonoyesno
Reflect.ownKeys(o) (ES2015) 〔►see JavaScript: Reflect.ownKeysnonoyesyes

〔►see JavaScript: Property Attributes

Array-Like Object to Array

〔►see JavaScript: Array-Like Object to Array

Iterable Object to Array

If the object is iterable, use:

Array.from(iterable)

〔►see JavaScript: Array.from

Array Topic

  1. JavaScript: Array Basics
  2. JavaScript: Understand JS Array
  3. JavaScript: Create Array
  4. JavaScript: Sparse Array
  5. JavaScript: Array-Like Object
  6. JavaScript: Array How-To

  1. JavaScript: Array Object
  2. JavaScript: Array.prototype
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.