Monday, September 24, 2018

Javascript - Loop through object new and old style.

var shanghai = {

  population: 14.35e6,

  longitude: '31.2000 N',

  latitude: '121.5000 E',

  country: 'CHN'

};

//OLD Simple
for(var prop in shanghai){

console.log(prop + ':'+ shanghai[prop] );

}
//NEW more complex
Object.keys(shanghai).forEach(e => console.log(`key=${e}  value=${shanghai[e]}`));

No comments:

Post a Comment