Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2020 13:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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: '',
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