Es8 has introduced a new cool feature called Object.values()
that can be used to get the values of an object.
with Object.values
instead of iterating through every element of object we can use it to return all values an object in array.
const cars = {
'Toyota': 'Camry',
'Ford': 'Fiesta',
'Honda': 'Civic'
};
const carsValue = Object.values(cars);
//['Camry', 'Fiesta', 'Civic']
Top comments (3)
You "can't" get object values iterating over the object because -allegedly- an Object is not an iterable in Javascript.
Of course as everything is an Object in JS (just like in Python or other languages) you can currently do some tricks like that:
I assume you were talking about that.
By the way you can also convert an Object into a key-value Array using
Object.entries
insteadObject.values
so you get both the key and the value:so you can do:
or
or
You can also play around with objects in even funnier ways like this DOPE thingy.
Hope you find that interesting, have a great day! 👌😁
Yes that what I were talking about, you could explain it better than me, I hope this will clear things up
have a great day
NP, If there's any JS-related topic in which I can help just tell me :)