Navigate back to the homepage

How to get all keys of object in javascript?

Infinitbility
JavaScript
December 21st, 2021 · 1 min read
How to get all keys of object in javascript?

Hello Friends 👋,

Welcome to Infinitbility.

Sometime we need get all keys of object, like validating objects details, manage object as daynamics keys and all values.

In this times, we need all keys list whitch we will use to get objects values.

Mostly, we need to maintain daynamic object whitch we don’t how much keys we get.

Now, let’s move to solution, how we get all keys and how to use them for get values from object in javascript.

let assume, we have below example object whitch we will use to get all keys example and use keys example.

1let User = {
2 id: 1,
3 name: "infinitbility",
4 slogan: "We have the ability to build infinite way for us.",
5 dob: "2021-07-26",
6 isActive: 1
7};

Javascript, Get all keys

Javascript provide Object.keys() method to get all keys in array, Yes it will return array of keys.

1let User = {
2 id: 1,
3 name: "infinitbility",
4 slogan: "We have the ability to build infinite way for us.",
5 dob: "2021-07-26",
6 isActive: 1
7};
8
9let userKeys = Object.keys(User);
10console.log("userKeys =>", userKeys);

Output

Javascript Get All keys Example
Javascript Get All keys Example

Javascript, Use retrived keys example

To use keys get using Object.keys() method, we will use loop of keys and pass each keys in object to get value.

1let User = {
2 id: 1,
3 name: "infinitbility",
4 slogan: "We have the ability to build infinite way for us.",
5 dob: "2021-07-26",
6 isActive: 1
7};
8
9let userKeys = Object.keys(User);
10console.log("userKeys =>", userKeys);
11
12for(let key of userKeys){
13 console.log(key, " => ", User[key]);
14}

Output

Javascript Use keys Example
Javascript Use keys Example

Thanks for reading…

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo

Tutorials

Categories

More articles from Infinitbility

How to assign object without reference in javascript?

How to assign object without reference in javascript?

Javascript, object assigning without reference example.

December 20th, 2021 · 1 min read
How to enable or disable screenshot in react native?

How to enable or disable screenshot in react native?

React Native screen capture secure example

December 7th, 2021 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]