Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 968309 of Object.values()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Object/values
  • Revision title: Object.values()
  • Revision id: 968309
  • Created:
  • Creator: x2357
  • Is current revision? No
  • Comment fix link

Revision Content

{{JSRef}} {{ES7}}

The Object.values() method returns an array of a given object's own enumerable property values, in the same order as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

Syntax

Object.values(obj)

Parameters

obj
The object whose enumerable own property values are to be returned.

Description

Object.values() returns an array whose elements are strings corresponding to the enumerable property values found directly upon object. The ordering of the properties is the same as that given by looping over the property values of the object manually.

Examples

var obj = { foo: "bar", baz: 42 };
console.log(Object.values(obj)); // ['bar', 42]

// array like object
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.values(obj)); // ['a', 'b', 'c']

// array like object with random key ordering
var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.values(an_obj)); // ['b', 'c', 'a']

// getFoo is property which isn't enumerable
var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; } } });
my_obj.foo = "bar";
console.log(Object.values(my_obj)); // ['bar']

// non-object argument will be coerced to an object
console.log(Object.values("foo")); // ['f', 'o', 'o']

Polyfill

To add compatible Object.values support in older environments that do not natively support it, you can find a Polyfill in the tc39/proposal-object-values-entries or in the es-shims/Object.values repositories.

Specifications

Specification Status Comment
{{SpecName('ESDraft', '#sec-object.values', 'Object.values')}} {{Spec2('ESDraft')}} Not included in the official draft yet. See this stage3 proposal for the current specification draft text.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}} {{CompatNightly("firefox")}} {{CompatNo}} {{CompatNo}} {{CompatNo}} [1]
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatNightly("firefox")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

[1] See bug 150131.

See also

  • Enumerability and ownership of properties
  • {{jsxref("Object.keys()")}}
  • {{jsxref("Object.entries()")}} {{experimental_inline}}
  • {{jsxref("Object.prototype.propertyIsEnumerable()")}}
  • {{jsxref("Object.create()")}}
  • {{jsxref("Object.getOwnPropertyNames()")}}

Revision Source

<div>{{JSRef}} {{ES7}}</div>

<p>The <code><strong>Object.values()</strong></code> method returns an array of a given object's own enumerable property values, in the same order as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
<code>Object.values(<var>obj</var>)</code></pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>obj</code></dt>
 <dd>The object whose enumerable own property values are to be returned.</dd>
</dl>

<h2 id="Description">Description</h2>

<p><code>Object.values()</code> returns an array whose elements are strings corresponding to the enumerable property values found directly upon <code>object</code>. The ordering of the properties is the same as that given by looping over the property values of the object manually.</p>

<h2 id="Examples">Examples</h2>

<pre class="brush: js">
var obj = { foo: "bar", baz: 42 };
console.log(Object.values(obj)); // ['bar', 42]

// array like object
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.values(obj)); // ['a', 'b', 'c']

// array like object with random key ordering
var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.values(an_obj)); // ['b', 'c', 'a']

// getFoo is property which isn't enumerable
var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; } } });
my_obj.foo = "bar";
console.log(Object.values(my_obj)); // ['bar']

// non-object argument will be coerced to an object
console.log(Object.values("foo")); // ['f', 'o', 'o']
</pre>

<h2 id="Polyfill">Polyfill</h2>

<p>To add compatible <code>Object.values</code> support in older environments that do not natively support it, you can find a Polyfill in the <a href="https://github.com/tc39/proposal-object-values-entries">tc39/proposal-object-values-entries</a> or in the <a href="https://github.com/es-shims/Object.values">es-shims/Object.values</a> repositories.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-object.values', 'Object.values')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>Not included in the official draft yet. See this <a href="https://github.com/tc39/proposal-object-values-entries">stage3 proposal</a> for the current specification draft text.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNightly("firefox")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}} [1]</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNightly("firefox")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] See <a href="https://bugs.webkit.org/show_bug.cgi?id=150131">bug 150131</a>.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties">Enumerability and ownership of properties</a></li>
 <li>{{jsxref("Object.keys()")}}</li>
 <li>{{jsxref("Object.entries()")}} {{experimental_inline}}</li>
 <li>{{jsxref("Object.prototype.propertyIsEnumerable()")}}</li>
 <li>{{jsxref("Object.create()")}}</li>
 <li>{{jsxref("Object.getOwnPropertyNames()")}}</li>
</ul>
Revert to this revision