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: 17}89let 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: 17}89let userKeys = {10 id: "id",11 name: "name",12 isActive: "isActive"13}1415for (let [key, value] of Object.entries(userKeys)) {16 console.log(value, users[value]);17}
Output

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.