The Object.values method generates an array that includes the enumerable property values belonging to the specified object. These values are arranged in the same sequence as they would appear when using a for...in loop.
Syntax:
Example
Object.values(obj)
Parameter:
obj: This refers to the object from which the enumerable own property values will be retrieved.
Return value:
This approach yields an array containing the values of the enumerable properties that belong to a specified object.
Browser Support:
| Chrome | 54 |
|---|---|
Edge |
14 |
| Firefox | 47 |
| Opera | 41 |
Example 1
Example
const object1 = {
a: 'Rahul',
b: 0,
c:false
};
console.log(Object.values(object1));
Output:
Output
["Rahul", 0, false]
Example 2
Example
const object1 = {
a: 'string',
b: 34,
c: true
};
const object2 = {
a: 'start',
b: 33,
c: false
};
console.log(Object.values(object1),
Object.values(object1));
Output:
Output
["string", 34, true]
["string", 34, true]
Example 3
Example
Object.values = function(object) {
var values = [];
for(var property in object) {
values.push(object[property]);
}
return values;
}
var foo = {a:1, b:2, c:3};
console.log(Object.values(foo));
Output:
Output
[1, 2, 3]