// Easy access to key and value :)
let myObj = {name: 'Jojo', family: 'Lopez'}
for (const [key, value] of Object.entries(myObj)) {
console.log('key is:', key);
console.log('value is:', value);
}
// key is: name
// value is: Jojo
// key is: family
// value is: Lopez
for (var key in validation_messages) {
// skip loop if the property is from prototype
if (!validation_messages.hasOwnProperty(key)) continue;
var obj = validation_messages[key];
for (var prop in obj) {
// skip loop if the property is from prototype
if (!obj.hasOwnProperty(prop)) continue;
// your code
alert(prop + " = " + obj[prop]);
}
}
function logArrayElements(element, index, array) {
console.log('a[' + index + '] = ' + element)
}
// Notice that index 2 is skipped, since there is no item at
// that position in the array...
[2, 5, , 9].forEach(logArrayElements)
// logs:
// a[0] = 2
// a[1] = 5
// a[3] = 9