How to iterate a Javascript Object
In many cases, we want to iterate over an Object for it's keys and respective values.
var obj = {
name:"John Doe",
age:23,
sex:"Male"
};
Object.entries(obj).forEach(([key,value])=>{
// console.log(key);
// console.log(value);
console.log(`KEY - ${key} | VALUE - ${value}`)
});
/*
KEY - name | VALUE - John Doe
KEY - age | VALUE - 23
KEY - sex | VALUE - Male
*/
More Programming from our blog
- How to remove Powered by 000webhost banner inside an iframe?
- How to use Facebook Comments Plugin on your website step by step explained
- [SOLVED] Cordova - App id contains a reserved word, or is not a valid identifier
- PHP check if a file or directory exists
- Streaming RTSP on a Web browser using ffmpeg