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.

let users = {
  id: 1,
  name: "infinitbility",
  age: 2,
  domain: "infinitbility.com",
  isActive: 1
}

let userKeys = {
  id: "id",
  name: "name",
  isActive: "isActive"
}

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

let users = {
  id: 1,
  name: "infinitbility",
  age: 2,
  domain: "infinitbility.com",
  isActive: 1
}

let userKeys = {
  id: "id",
  name: "name",
  isActive: "isActive"
}

for (let [key, value] of Object.entries(userKeys)) {
  console.log(value, users[value]);
}

Output

Javascript, dynamic, property, accesss, example
Javascript, dynamically object value access example.

Thanks for reading…