C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.values() MethodThe Object.values() returns an array which contains the given object's own enumerable property values, in the same order as that provided by a for...in loop. Syntax:
Object.values(obj) Parameter:
obj: It is the object whose enumerable own property values are to be returned. Return value:
This method returns an array of a given object's own enumerable property value. Browser Support:
Example 1
const object1 = {
a: 'Rahul',
b: 0,
c:false
};
console.log(Object.values(object1));
Output: ["Rahul", 0, false] Example 2
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: ["string", 34, true] ["string", 34, true] Example 3
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: [1, 2, 3]
Next TopicJavaScript Objects
|