Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2020 13:37
What would you like to do?
Using for in construct to iterate over an object data structure`
const person = {
firstName: 'Virat',
lastName: 'Kohli',
email: '',
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:
// 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