How to loop through object values using Object.values() in JavaScript

published: 14 May 2022

2 min read

How to loop through object values using Object.values() in JavaScript

The Object.values() method was introduced in ES8 and it does the opposite of the Object.key() method.

The Object.values() method returns the values of all properties in the object as an array. You can then loop through the values array by using any of the array looping methods.

Here is an example:

const animals = {
  tiger: '🐅',
  cat: '🐱',
  monkey: '🐒',
  elephant: '🐘'
}

// iterate over object values
Object.values(animals).forEach(val => console.log(val))

// 🐅
// 🐱
// 🐒
// 🐘

Read this article to learn more about different ways of iterating over an object in JavaScript.

How to loop through object values using Object.values() in JavaScript | Coding Tips And Tricks

Are we missing something?  Help us improve this article. Reach out to us.

Are you looking for other code tips?

Check out what's on in the category: javascript, programming
Check out what's on in the tag: javascript, programming, array