Using for in construct to iterate over an object data structure`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
firstName: 'Virat', | |
lastName: 'Kohli', | |
email: 'vk@rcb.in', | |
profession: 'Cricketer', | |
team: 'India/RCB' | |
} | |
for(attr in person) { | |
console.log(`Attribute: ${attr} Value: ${person[attr]}`); | |
} | |
// Output | |
// Attribute: firstName Value: Virat | |
// Attribute: lastName Value: Kohli | |
// Attribute: email Value: vk@rcb.in | |
// Attribute: profession Value: Cricketer | |
// Attribute: team Value: India/RCB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment