#100DaysOfCode Day 14: Object.keys & Object.values

Shawn McMahon
2 min readJul 25, 2021

Day 14: Object.keys & Object.values

Today is dedicated to Object.keys and Object.values.

Source: https://www.pexels.com/photo/close-up-photo-of-two-brown-and-beige-guinea-pigs-1093126/

Object.keys

Object.keys takes in an object as an input. It outputs an array of all of the keys within an object. Objects are made of key-value pairs. A key-value pair is a line of data with two data points. A key is a label or name for a piece of data. A value is a data type that describes the key. A value can be a number, a string, a function, and so on. If I have 100 oranges; Oranges would be the key and 100 would be the value. Consider the example below. We have an inventory object. The keys are the items in our inventory (books, pens, rulers). To retrieve an array of keys, simply input the object as an argument inside Object.keys(object).

Object.keys and Object.values code snippet examples
Object.keys and Object.values examples
Object.keys and Object.values code snippet examples

Object.values

Why is this useful?

We’ve talked about array iterator methods a lot in the last week. They make my life as a dev a whole lot easier! But what happens when our data is in an object? Are there object iterator methods in Javascript? Sadly no — I wish there were. But if we need data inside these objects, we can pull out the data by creating arrays with these tools. And then we can reach for the array iterator method we need to get the job done.

--

--