Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Object.values()

BaselineWidely available

TheObject.values() static method returns an array of a given object's own enumerable string-keyed property values.

Try it

const object1 = {  a: "some string",  b: 42,  c: false,};console.log(Object.values(object1));// Expected output: Array ["some string", 42, false]

Syntax

js
Object.values(obj)

Parameters

obj

An object.

Return value

An array containing the given object's own enumerable string-keyed property values.

Description

Object.values() returns an array whose elements are values of enumerable string-keyed properties found directly uponobject. This is the same as iterating with afor...in loop, except that afor...in loop enumerates properties in the prototype chain as well. The order of the array returned byObject.values() is the same as that provided by afor...in loop.

If you need the property keys, useObject.keys() instead. If you need both the property keys and values, useObject.entries() instead.

Examples

Using Object.values()

js
const obj = { foo: "bar", baz: 42 };console.log(Object.values(obj)); // ['bar', 42]// Array-like objectconst arrayLikeObj1 = { 0: "a", 1: "b", 2: "c" };console.log(Object.values(arrayLikeObj1)); // ['a', 'b', 'c']// Array-like object with random key ordering// When using numeric keys, the values are returned in the keys' numerical orderconst arrayLikeObj2 = { 100: "a", 2: "b", 7: "c" };console.log(Object.values(arrayLikeObj2)); // ['b', 'c', 'a']// getFoo is a non-enumerable propertyconst myObj = Object.create(  {},  {    getFoo: {      value() {        return this.foo;      },    },  },);myObj.foo = "bar";console.log(Object.values(myObj)); // ['bar']

Using Object.values() on primitives

Non-object arguments arecoerced to objects.undefined andnull cannot be coerced to objects and throw aTypeError upfront. Only strings may have own enumerable properties, while all other primitives return an empty array.

js
// Strings have indices as enumerable own propertiesconsole.log(Object.values("foo")); // ['f', 'o', 'o']// Other primitives except undefined and null have no own propertiesconsole.log(Object.values(100)); // []

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-object.values

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp