Navigate back to the homepage

How to get object value using the dynamic key in javascript?

Infinitbility
JavaScript
February 10th, 2022 · 1 min read
keep affilitate

Hello Friends 👋,

Welcome To Infinitbility! ❤️

Let’s assume we have a user object that store all user details key value-based and I have another object that store which property value we need from the object user.

Here, we have to assume also seconds object data will changes at any time i.e we need dynamic key logic in javascript.

So, we have to get user keys in seconds which we will use to get value from the first user object.

Let’s start.

Here, we have user object and userkeys object.

1let users = {
2 id: 1,
3 name: "infinitbility",
4 age: 2,
5 domain: "infinitbility.com",
6 isActive: 1
7}
8
9let userKeys = {
10 id: "id",
11 name: "name",
12 isActive: "isActive"
13}

Now, we will use userKeys object value to access users’ property let’s see how we can do it?

1let users = {
2 id: 1,
3 name: "infinitbility",
4 age: 2,
5 domain: "infinitbility.com",
6 isActive: 1
7}
8
9let userKeys = {
10 id: "id",
11 name: "name",
12 isActive: "isActive"
13}
14
15for (let [key, value] of Object.entries(userKeys)) {
16 console.log(value, users[value]);
17}

Output

Javascript, dynamic, property, accesss, example
Javascript, dynamically object value access 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.

melio affilitate

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 Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to get array length in react native?

React Native, get length of array example.

February 9th, 2022 · 1 min read

How to get current UTC date in typescript?

TypeScript, get current UTC date example.

February 8th, 2022 · 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]