Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Object.values

Returns an array of an object's property values.

Available since: ES2017

Syntax

Object.values(obj)

Parameters

ParameterTypeDescription
objobjectThe object whose values you need.

Return value

ArrayAn array of the object's own property values.

Examples

Property values:

const prices = { tea: 3, coffee: 5, cake: 7 };
 
console.log(Object.values(prices));

Output:

[
  3,
  5,
  7
]

The sum of all values:

const prices = { tea: 3, coffee: 5, cake: 7 };
 
console.log(Object.values(prices).reduce((sum, price) => sum + price, 0));

Output:

15

Notes

The order is the same as in Object.keys(): integer-like keys in ascending order first, then the rest in insertion order.

See also

Related recipes

In the tutorial

Thanks for reading!

Donate to the site — we work hard for you.