Skip to main content

Explore your training options in 10 minutes

JavaScript: Object.values(): A Complete Guide

Christina Kopecky - January 22, 2021

The JavaScript Object.values() method retrieves a list of the values in an object. You can iterate over the result of the values() method to see the contents of each value in the object.

Objects contain keys and values. Sometimes, you will only want to retrieve the values in the object. Say we have an object which stores the names of all the people on a leaderboard. We may only want to retrieve their names from the object rather than the keys associated with their names (i.e. their positions).

That’s where the Object.values() method comes in. This method lets you see all the values in an object. In this guide, we’re going to discuss how to use the Object.values() method. We’ll refer to a detailed example to help you get started.

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

JavaScript Object.values()

The JavaScript Object.values() method takes in the object and returns its enumerable properties in an array. Values are ordered as if you were to loop over the object manually and push them into an array.

Let’s take a look at the syntax for this method:

let players = {
	a: "lucy",
	b: "harry"


The Object.values() method accepts one argument: the name of the object whose values you want to see. In this syntax, we print the result of the method to the console.

This code returns the names of the players in our JavaScript object : lucy and harry . These names are returned in a list, which we print to the JavaScript console :

["lucy", "harry"]

Notice that the values are in the same order as they were in the dictionary.

The Object.values() method is an easy way to retrieve values from an object. The alternative is to create a new list and iterate over the object with a for loop, adding each value to the new list. This method takes more time and more code to write.

Let’s look at an example of this method in action.

Object.values() JavaScript Example

Suppose we have an object that contains information about San Jose, a city in California. We want to retrieve all the information about this city without retrieving the labels associated with each piece of data.

Consider this key-value pair:

city: "San Jose",

We only want to retrieve the city name, rather than the label city .

Let’s take a look at a program that will let us do this:

Venus, a software engineer at Rockbot

"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"

Venus, Software Engineer at Rockbot

<!DOCTYPE html>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width">
   <div id="root"></div>
  <script async defer>
   const cityData =  {
     city: "San Jose",
     state: "California",
     area: 181.36,
     land: 178.24,
     water: 3.12,
     urban: 342.27,
     metro: 2694.61,
     elevation: 82,
     population: 1021795,
     timezone: "Los_Angeles/Pacific",
     website: ""
   let arr = Object.values(cityData);
   let root = document.getElementById('root');
   root.innerHTML = JSON.stringify(arr);

First, we set up a standard HTML page with a <head> tag, a <body> tag, and some basic meta information in the <head> tag.

We use a <script> tag in which we write our JavaScript code. Within this tag, we declare a JavaScript object. This object is called cityData .

Next, we retrieve the values in this object using the Object.values() method. We then select a HTML <div> tag with the id root in our code. This is the use case for the JavaScript getElementById method above.

After we select this <div> tag, we replace the contents of the <div> tag with the result of the Object.values() method.

Our code returns a list:

["San Jose","California", 181.36, 178.24, 3.12, 342.27, 2694.61, 82, 1021795, "Los_Angeles/Pacific", ""]

We can see all of the values in our original object. These values are stored as a list.


The JavaScript Object.values() method returns a list of the values in an object. This method accepts one argument: the name of the object from which you want to retrieve values.

Do you want to learn more about coding in JavaScript? Check out our How to Learn JavaScript guide . You’ll find top learning tips and a list of courses for beginner and intermediate-level developers.

Check out these tutorials if you want to learn more about JavaScript objects:

JavaScript Object.keys(): A Guide

JavaScript Objects: A Guide

JavaScript Class: A Guide

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

What's Next?

Christina Kopecky

About the author: Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy,, and Educative.

Skip to main content