Object.values() Method – Copy an Object's Values into an Array
Whenever you use Object.values() on a JavaScript object, the method does the following:
- It creates a new array.
- It copies the specified object’s enumerable own values into the newly created array.
- It returns the new array containing items representing the given object’s values.
Syntax of the Object.values()
Method
Object.values()
accepts a single argument. Here’s the syntax:
The objectArgument
refers to the JavaScript object whose values you want to extract into a new array.
Examples of the Object.values()
Method
Below are examples of the Object.values()
method.
Copy an object’s values into a new array
Copy an array’s values into a new array
Copy a string’s values into a new array
The Object.values()
method successfully extracted the string’s values because strings are the only primitive data with enumerable own properties.