DEV Community

Christian Falucho
Christian Falucho

Posted on • Updated on

Day 12 of #100DaysOfCode!

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"]
console.log(Object.values(computers))
//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"
}
console.log(Object.values(books))
//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.

Top comments (0)