Iterate over values of an object with ES2017 Object.values()

Akash Gutha
InstructorAkash Gutha
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

This lesson take an extensive look at the addition of the Object.values functions, how they can be used to gather information about the values of an object’s own enumerable string-key properties

Instructor: [00:00] Let's look at the object.values method that's introduced in ES2017. Let's describe our day using an object. We'll add in properties like wake-up time and make it equal to the new date. Let's also add a list of gadgets, laptop and phone.

[00:17] Now, let's capture the actual values from the object using object.values method. Here, we'll pass in our day object. Then, we'll go ahead and log the values that we have captured. Now, let's go to the terminal and run our index file in node.

[00:36] You can see that it outputs a list of objects. You can see that the first one is the value of wake-up time that is the new date, and the second one is the value of gadgets that is the array of laptop and phone.

[00:51] Let's test the same for functions. We'll add a function called as goToWork and we'll simply console log work inside it. Now, if we go ahead and run this file in node, you can see that it outputs a function with the name goToWork in the list of objects.

egghead
egghead
~ 6 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today