Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created September 22, 2020 13:37
Show Gist options
  • Save scriptschat/2526d61ba0a1c1e25da41197c8a0d1d1 to your computer and use it in GitHub Desktop.
Save scriptschat/2526d61ba0a1c1e25da41197c8a0d1d1 to your computer and use it in GitHub Desktop.
Using for in construct to iterate over an object data structure`
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