Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
JavaScript

JavaScript Object.values() Method

  • 18 Sep, 2025
  • Com 1
JavaScript Object.values() Method

JavaScript Object.values() is a static method that returns an array of a given object’s own enumerable property values, in the same order as provided by a for…in loop (excluding prototype chain properties).

Getting the values of an Object in JavaScript

const gadget = { device: "iPhone17", chip: "A19", price: 1000 };

console.log(Object.values(gadget));

// Output: [ 'iPhone17', 'A19', 1000 ]

In this code, we log the values of a “gadget” object in an array. For fetching an array of keys, use Object.keys() method.

One thing to note is that only properties with the enumerable attribute set to true are included in the output values array.

Syntax

Object.values(obj)

Parameters

Argument Description
obj (required) It represents an object from which to extract the enumerable own property values.

Non-enumerable properties

Let’s create an Object with an enumerable property set to false and see if it appears in the output values array.

const obj = {};

Object.defineProperty(obj, 'hidden', {
    value: 'secret',
    enumerable: false
});

Object.defineProperty(obj, 'visible', {
    value: 'data',
    enumerable: true
});

console.log(Object.values(obj));

// Output: [ 'data' ]

In this code, we defined a property “hidden” for the object, but we set enumerable to false. Then, we added another property to the obj and set the enumerable to true. By default, for each property, enumerable is set to true if you add a property using dot (.) notation.

If you examine the output values array, it displays only the “data” value because its enumerable property value is set to true; however, the “hidden” property has an enumerable value of false. So, it was not included in the output array.

Numeric keys ordering

Numeric keys are treated as indices and sorted in ascending order, regardless of insertion order.

Numeric keys ordering in JavaScript

const scores = { '2': "second", '10': "ten", '1': "eleven" };

console.log(Object.values(scores));

// Output: [ 'eleven', 'second', 'ten' ]

The output array is based on the numeric string keys. It is sorted in ascending order based on the keys.

This mimics array behavior but applies to objects.

Arrays (Special case of objects)

Arrays are also objects, and their keys are numeric keys (0, 1, 2), which are enumerable.

If the input is an array, the Object.values() method returns the elements in index order.

Arrays (Special case of objects)

const arr = ['iphone', 'watch', 'ipod'];

console.log(Object.values(arr));

// Output: [ 'iphone', 'watch', 'ipod' ]

Inherited Properties

The .values() method ignores inherited properties and only counts its own properties.

const parent = { inherited: 'from parent' };

const child = Object.create(parent);

child.own = 'from child';

console.log(Object.values(child));

// Output: ['from child']

That’s all!

Post Views: 8
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

JavaScript Object.assign() Method
None (Null) in Python: What is it and Why is it useful?

1 Comment

  1. Azmi

    September 18, 2019 at 9:10 pm

    This was helpful. Thanks 🙂

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend