return object in es6 foreach over code example
Example 1: foreach object javascript
const obj = {
name: 'Jean-Luc Picard',
rank: 'Captain'
};
// Prints "name Jean-Luc Picard" followed by "rank Captain"
Object.entries(obj).forEach(entry => {
const [key, value] = entry;
console.log(key, value);
});
Example 2: js foreach key value
Object.keys(obj).forEach(function (key) {
// do something with obj[key]
});