FrontendDeveloper.in

ECMAScript question detail

Object values

Similar to Object.keys which iterate over JavaScript object’s keys, Object.values will do the same thing on values. i.e, The Object.values() method is introduced to returns an array of a given object's own enumerable property values in the same order as for...in loop.

const countries = {
IN: 'India',
SG: 'Singapore',
}
Object.values(countries) // ['India', 'Singapore']

By the way, non-object argument will be coerced to an object

console.log(Object.values(['India', 'Singapore'])); // ['India', 'Singapore']
console.log(Object.values('India')); // ['I', 'n', 'd', 'i', 'a']
Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399