It's not true in the general case that you'll get the same result from Array.from(x) and Object.values(x) when x is an iterable object. In fact, it's fairly rare (just arrays and array-likes¹ that hide their length property by making it non-enumerable or inheriting it and don't have any other own, enumerable properties). Array.from will loop through the iterable object using iteration; Object.values will loop through the object looking for own, enumerable properties. For an array that doesn't have any non-array properties, that ends up being the same thing, but it's not true in the general case.

In the general case, Array.from and Object.values do very different things and have different results:

  • Array.from creates an array from any iterable or array-like object (an object with a length and index properties like 0 and 1).

  • Object.values creates an array of the values of an object's own enumerable properties. The object doesn't have to be iterable (Object.values doesn't even look to see if it is.)

  • Array.from accepts a second argument, a function that can be used to map the values from the iterable/array-like into new values for the array.

Here's an example where Object.values gets [] (because the Set has no own enumerable properties) but Array.from gets [1, 2, 3] (because the Set's iterator provides those three values):

const x = new Set([1, 2, 3]);

// Shows an empty array
console.dir(Object.values(x));
// Shows [1, 2, 3]
console.dir(Array.from(x));

Conversely, here's one where Object.values returns [1, 2, 3] because the object has those as own enumerable properties, but Array.from returns [] because the object is neither iterable nor array-like:

const x = {a: 1, b: 2, c: 3};

// Shows [1, 2, 3];
console.dir(Object.values(x));
// Shows []
console.dir(Array.from(x));


¹ An array-like object is an object with:

  • A length property
  • Properties named with strings that are numbers in the normal decimal form for the values 0 through length - 1 (but there can be gaps).

For instance, this is an array-like object:

const obj = {0: "zero", 1: "one", length: 2};

(I've used number literals for the property names, but they'll be converted to string.)

Note that that object will give you different results for Array.from and Object.values because length is an own, inherited property.

Answer from T.J. Crowder on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_object_values.asp
JavaScript Object.values() Method
The Object.values() method returns an array of the property values of an object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › values
Object.values() - JavaScript | MDN
5 days ago - The Object.values() static method returns an array of a given object's own enumerable string-keyed property values.
Discussions

javascript - Object.values vs Array.from, what's the difference? - Stack Overflow
I recently faced issues where I couldn't use .map on iterable objects and had to convert them to arrays with either Object.values or Array.from I seem to get same result in both cases, so I'm wonde... More on stackoverflow.com
🌐 stackoverflow.com
function - Get values from an object in JavaScript - Stack Overflow
How can I get values from data independent of property names? ... This is an Object, not an Array. More on stackoverflow.com
🌐 stackoverflow.com
How to get all properties values of a JavaScript Object (without knowing the keys)? - Stack Overflow
If there is a JavaScript object: var objects={...}; Suppose, it has more than 50 properties, without knowing the property names (that's without knowing the 'keys') how to get each property value i... More on stackoverflow.com
🌐 stackoverflow.com
How to Access Object value with Javascript?
Find answers to How to Access Object value with Javascript? from the expert community at Experts Exchange More on experts-exchange.com
🌐 experts-exchange.com
June 4, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-object-values-method
JavaScript Object values() Method - GeeksforGeeks
Object.values() takes the object as an argument of which the enumerable property values are to be returned and returns an array containing all the enumerable property values of the given object.
Published: July 12, 2024
Top answer
1 of 2
4

It's not true in the general case that you'll get the same result from Array.from(x) and Object.values(x) when x is an iterable object. In fact, it's fairly rare (just arrays and array-likes¹ that hide their length property by making it non-enumerable or inheriting it and don't have any other own, enumerable properties). Array.from will loop through the iterable object using iteration; Object.values will loop through the object looking for own, enumerable properties. For an array that doesn't have any non-array properties, that ends up being the same thing, but it's not true in the general case.

In the general case, Array.from and Object.values do very different things and have different results:

  • Array.from creates an array from any iterable or array-like object (an object with a length and index properties like 0 and 1).

  • Object.values creates an array of the values of an object's own enumerable properties. The object doesn't have to be iterable (Object.values doesn't even look to see if it is.)

  • Array.from accepts a second argument, a function that can be used to map the values from the iterable/array-like into new values for the array.

Here's an example where Object.values gets [] (because the Set has no own enumerable properties) but Array.from gets [1, 2, 3] (because the Set's iterator provides those three values):

const x = new Set([1, 2, 3]);

// Shows an empty array
console.dir(Object.values(x));
// Shows [1, 2, 3]
console.dir(Array.from(x));

Conversely, here's one where Object.values returns [1, 2, 3] because the object has those as own enumerable properties, but Array.from returns [] because the object is neither iterable nor array-like:

const x = {a: 1, b: 2, c: 3};

// Shows [1, 2, 3];
console.dir(Object.values(x));
// Shows []
console.dir(Array.from(x));


¹ An array-like object is an object with:

  • A length property
  • Properties named with strings that are numbers in the normal decimal form for the values 0 through length - 1 (but there can be gaps).

For instance, this is an array-like object:

const obj = {0: "zero", 1: "one", length: 2};

(I've used number literals for the property names, but they'll be converted to string.)

Note that that object will give you different results for Array.from and Object.values because length is an own, inherited property.

2 of 2
0

Array.from creates a new array, usually from another array, but can also be used on Set. It also has a second arguments, that allows to map each element to another value.

Object.values on the other hand creates a new array with the values from the supplied object.

I'm not exactly sure why you say they do the same thing, as they don't. Except maybe the fac that you end up with an array as the results. Take this example for instance:

Object.values({a: 2, b:3}) // will return [2, 3]

on the other hand

Array.from({a: 2, b:3}) // will return [], as an object is not an array-like object
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Working_with_objects
Working with objects - JavaScript | MDN
August 21, 2026 - For example, this example creates an object named myCar, with properties named make, model, and year, with their values set to "Ford", "Mustang", and 1969: ... Like JavaScript variables, property names are case sensitive. Property names can only be strings or Symbols — all keys are converted to strings unless they are Symbols.
Find elsewhere
🌐
Career Karma
careerkarma.com › blog › javascript › javascript: object.values(): a complete guide
JavaScript: Object.values(): A Complete Guide| Career Karma
January 22, 2021 - The Object data type has a values method that works to push the values of the key:value pair to an array and returns it.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › entries
Object.entries() - JavaScript | MDN
4 days ago - If you only need the property keys, use Object.keys() instead. If you only need the property values, use Object.values() instead.
🌐
DEV Community
dev.to › edriso › javascript-object-methods-a-practical-guide-2on4
JavaScript Object Methods - A Practical Guide - DEV Community
February 22, 2026 - Returns an array of [key, value] pairs. The most powerful of the three. Object.entries(pie); // [["name", "Apple Pie"], ["category", "Dessert"], ["servings", 8], ...]
🌐
Medium
medium.com › @ericvanrees › accessing-object-properties-and-values-in-javascript-bd2b13d8b61f
Accessing Object Properties and Values in JavaScript | by Eric van Rees | Medium
August 5, 2023 - We need to use brackets and an index number to access the object inside the array. Without these, you’ll console.log() will print undefined. Now let’s try a simple for loop to access properties and values inside the array’s object.
🌐
DevGenius
blog.devgenius.io › object-in-javascript-a-comprehensive-guide-5bd50cf5a4d9
Object in JavaScript: A Comprehensive Guide | by Tajammal Maqbool | Dev Genius
September 5, 2024 - The key is always a string or a symbol (Symbol is not a popular way to make a key), while the value can be any type of data, including numbers, strings, arrays, functions, or even other objects.
🌐
Quora
quora.com › How-can-you-use-the-Object-keys-Object-values-and-Object-entries-methods-to-access-the-properties-and-values-of-an-object-in-JavaScript
How to use the Object.keys, Object.values, and Object.entries methods to access the properties and values of an object in JavaScript - Quora
Answer: [code]const myObject = { a: 1, b: 2, c: 3 }; // Using Object.keys to get property names const keys = Object.keys(myObject); console.log(keys); // Output: ['a', 'b', 'c'] // Using Object.values to get property values const values = Object.values(myObject); console.log(values); // Outpu...
🌐
Facebook
facebook.com › codekinda › posts › javascript-object-values-is-for-what-exactly › 991138690629372
JavaScript Object . values() is for what exactly?
Explore the things you love · Log into Facebook · English (US) · فارسی · العربية · Türkçe · Deutsch · Français (France) · Polski · More languages…
🌐
Codecademy
codecademy.com › learn › game-dev-learn-javascript-objects › modules › game-dev-learn-javascript-objects › cheatsheet
Learn JavaScript: Objects: Learn JavaScript: Objects Cheatsheet | Codecademy
It uses a pair of curly braces ({}) with property names on the left-hand side of an assignment to extract values from objects. The number of variables can be less than the total properties of an object.
🌐
Medium
medium.com › @conboys111 › how-do-object-keys-object-values-and-object-entries-differ-in-javascript-8d1c19901ecb
Medium
September 27, 2024 - With Object.entries(), I’m getting an array of arrays, where each entry holds both the key and the value. It’s the complete package — the tag and the artifact together, in the same order we’ve been following: numbers first, then the rest in the order they were added. So, what did I learn from the museum that applies to JavaScript?
Top answer
1 of 16
1166

Depending on which browsers you have to support, this can be done in a number of ways. The overwhelming majority of browsers in the wild support ECMAScript 5 (ES5), but be warned that many of the examples below use Object.keys, which is not available in IE < 9. See the compatibility table.

ECMAScript 3+

If you have to support older versions of IE, then this is the option for you:

for (var key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
        var val = obj[key];
        // use val
    }
}

The nested if makes sure that you don't enumerate over properties in the prototype chain of the object (which is the behaviour you almost certainly want). You must use

Object.prototype.hasOwnProperty.call(obj, key) // ok

rather than

obj.hasOwnProperty(key) // bad

because ECMAScript 5+ allows you to create prototypeless objects with Object.create(null), and these objects will not have the hasOwnProperty method. Naughty code might also produce objects which override the hasOwnProperty method.

ECMAScript 5+

You can use these methods in any browser that supports ECMAScript 5 and above. These get values from an object and avoid enumerating over the prototype chain. Where obj is your object:

var keys = Object.keys(obj);

for (var i = 0; i < keys.length; i++) {
    var val = obj[keys[i]];
    // use val
}

If you want something a little more compact or you want to be careful with functions in loops, then Array.prototype.forEach is your friend:

Object.keys(obj).forEach(function (key) {
    var val = obj[key];
    // use val
});

The next method builds an array containing the values of an object. This is convenient for looping over.

var vals = Object.keys(obj).map(function (key) {
    return obj[key];
});

// use vals array

If you want to make those using Object.keys safe against null (as for-in is), then you can do Object.keys(obj || {})....

Object.keys returns enumerable properties. For iterating over simple objects, this is usually sufficient. If you have something with non-enumerable properties that you need to work with, you may use Object.getOwnPropertyNames in place of Object.keys.

ECMAScript 2015+ (A.K.A. ES6)

Arrays are easier to iterate with ECMAScript 2015. You can use this to your advantage when working with values one-by–one in a loop:

for (const key of Object.keys(obj)) {
    const val = obj[key];
    // use val
}

Using ECMAScript 2015 fat-arrow functions, mapping the object to an array of values becomes a one-liner:

const vals = Object.keys(obj).map(key => obj[key]);

// use vals array

ECMAScript 2015 introduces Symbol, instances of which may be used as property names. To get the symbols of an object to enumerate over, use Object.getOwnPropertySymbols (this function is why Symbol can't be used to make private properties). The new Reflect API from ECMAScript 2015 provides Reflect.ownKeys, which returns a list of property names (including non-enumerable ones) and symbols.

Array comprehensions (do not attempt to use)

Array comprehensions were removed from ECMAScript 6 before publication. Prior to their removal, a solution would have looked like:

const vals = [for (key of Object.keys(obj)) obj[key]];

// use vals array

ECMAScript 2017+

ECMAScript 2016 adds features which do not impact this subject. The ECMAScript 2017 specification adds Object.values and Object.entries. Both return arrays (which will be surprising to some given the analogy with Array.entries). Object.values can be used as is or with a for-of loop.

const values = Object.values(obj);

// use values array or:

for (const val of Object.values(obj)) {
    // use val
}

If you want to use both the key and the value, then Object.entries is for you. It produces an array filled with [key, value] pairs. You can use this as is, or (note also the ECMAScript 2015 destructuring assignment) in a for-of loop:

for (const [key, val] of Object.entries(obj)) {
    // use key and val
}

Object.values shim

Finally, as noted in the comments and by teh_senaus in another answer, it may be worth using one of these as a shim. Don't worry, the following does not change the prototype, it just adds a method to Object (which is much less dangerous). Using fat-arrow functions, this can be done in one line too:

Object.values = obj => Object.keys(obj).map(key => obj[key]);

which you can now use like

// ['one', 'two', 'three']
var values = Object.values({ a: 'one', b: 'two', c: 'three' });

If you want to avoid shimming when a native Object.values exists, then you can do:

Object.values = Object.values || (obj => Object.keys(obj).map(key => obj[key]));

Finally...

Be aware of the browsers/versions you need to support. The above are correct where the methods or language features are implemented. For example, support for ECMAScript 2015 was switched off by default in V8 until recently, which powered browsers such as Chrome. Features from ECMAScript 2015 should be be avoided until the browsers you intend to support implement the features that you need. If you use babel to compile your code to ECMAScript 5, then you have access to all the features in this answer.

2 of 16
514

By using a simple for..in loop:

for(var key in objects) {
    var value = objects[key];
}
🌐
Experts Exchange
experts-exchange.com › questions › 29102693 › How-to-Access-Object-value-with-Javascript.html
Solved: How to Access Object value with Javascript? | Experts Exchange
June 4, 2018 - myObj = { "name":"John", "age":30, "cars": { "car1":"Ford", "car2":"BMW", "car3":"Fiat" } } You can access nested JSON objects by using the dot notation or bracket notation: x = myObj.cars.car2; //or: x = myObj.cars["car2"]; ... Log in or create a free account to see answer. Signing up is free and takes 30 seconds. No credit card required. ... EARN REWARDS FOR ASKING, ANSWERING, AND MORE. Earn free swag for participating on the platform. ... JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers.
🌐
Swagger
swagger.io › specification
OpenAPI Specification - Version 3.2 | Swagger
When showing serialized examples, such as with the Example Object’s serializedValue or externalValue fields, in most cases the value to show is just the value, with all relevant percent-encoding or other encoding/escaping applied, and also including any delimiters produced by the style and explode configuration.
🌐
the murmurous sea
themurmuroussea.tistory.com › 89
JS: Object.keys() & Object.values() & Object.entries()
April 15, 2021 - : The ordering of the properties is the same as that given by looping over the property values of the object manually. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values