JavaScript(JS) object method - values

The Object.values() method is a built-in method of the JavaScript Object constructor. It returns an array of the values of the enumerable properties of the specified object in the order that they were inserted. This method is useful for obtaining an array of the values of an object's properties.

Here's the syntax:

refer‮i:ot ‬giftidea.com
Object.values(obj)

where obj is the object to get the values of.

Here's an example that shows how to use the Object.values() method:

const myObj = { prop1: "value1", prop2: "value2" };
const valuesArray = Object.values(myObj);
console.log(valuesArray); // ["value1", "value2"]

In this example, we create an object myObj with two properties prop1 and prop2. We use the Object.values() method to get an array of the values of myObj's properties. The resulting array is ["value1", "value2"].

It's important to note that the Object.values() method only returns the values of the enumerable properties of an object. Non-enumerable properties and properties inherited from prototypes are not included in the resulting array.

The Object.values() method is a useful tool for obtaining an array of the values of an object's properties. It can be used in combination with other methods such as Object.keys() to obtain an array of the keys and values of an object's properties.