foreach in an object javascript code example
Example 1: foreach object javascript
const obj = {
name: 'Jean-Luc Picard',
rank: 'Captain'
};
Object.entries(obj).forEach(entry => {
const [key, value] = entry;
console.log(key, value);
});
Example 2: javascript foreach in object
for (var key in validation_messages) {
if (!validation_messages.hasOwnProperty(key)) continue;
var obj = validation_messages[key];
for (var prop in obj) {
if (!obj.hasOwnProperty(prop)) continue;
alert(prop + " = " + obj[prop]);
}
}