DEV Community


Day 12 of #100DaysOfCode!

Christian Falucho
Passionate about building websites and web applications that can be used by millions of people. I hope to build tools that can help people.
Updated on ・1 min read

Today's progress

Today I worked on Object.values()

What I learned

The Object.values() method returns an array of enumerable property values in the same order that the properties were manually given. Think of the the order similar to that of a for loop.

Let's take a better look at how this works with code.

let computers = ["MacBook Pro", "Dell XPS", "Lenovo", "Surface Pro"]
//output: ["MacBook Pro", "Dell XPS", "Lenovo", "Surface Pro"]

Enter fullscreen mode Exit fullscreen mode

With the above code we have an array of computers and then we use Object.values() and pass in the parameter computers. Next, when we do a console.log. You'll notice how it returns an array of the object's own enumerable property values.

Another example...
let books = {
    0: "Mindset",
    1: "Boundless",
    2: "48 Laws of Power"
//output: ["Mindset", "Boundless", "48 Laws of Power"]
Enter fullscreen mode Exit fullscreen mode

Here, we have an array like objects and when we use the method Object.values() on books it returns an array of enumerable property values.

In conclusion

The method Object.values() can be a great tool to return enumerable property values in an array.

Discussion (0)