Categories
JavaScript Answers

How to fix Uncaught TypeError: Object.values is not a function JavaScript?

Spread the love

To fix Uncaught TypeError: Object.values is not a function JavaScript, we can use Object.keys instead.

For instance, we write

const vals = Object.keys(countries).map((key) => {
  return countries[key];
});

to get the keys from the countries object with Object.keys.

Then we call map with a callback to get the value from each key in countries and return the array of values.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *