If there is an 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 in a loop?
If there is an 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 in a loop?
If you have access to Underscore.js, you can use the
_.values
function like this:I realize I'm a little late but here's a shim for the new firefox 47
Object.values
methodHere's a function similar to PHP's array_values()
Here's how to get the object's values if you're using ES6 or higher:
Object.entries do it in better way.
If you really want an array of Values, I find this cleaner than building an array with a for ... in loop.
ECMA 5.1+
It's worth noting that in most cases you don't really need an array of values, it will be faster to do this:
This iterates over the keys of the Object o. In each iteration k is set to a key of o.
By using a simple
for..in
loop: