Object.keys

Object.keys

The Object.keys method converts an object into an array of its keys.

So you will end up with an array of all the property keys in an object.

For example if you have an object containing a few trees where the keys are the names of the trees and the values are the number of trees you have and you pass it into Object.keys then it will return an array of the names of all the trees.

{ oak: 2, ash: 3, maple: 4 } => [ "oak", "ash", "maple"]

Further resources

Related topics

© 2024 MWXYZ