foreach object javascript

JavaScript
Object.keys(obj).forEach(function(key) {
  console.log(key, obj[key]);
});const list = {
  key: "value",
  name: "lauren",
  email: "[email protected]",
  age: 30
};

// Object.keys returns an array of the keys
// for the object passed in as an argument.

Object.keys(list).forEach(val => {
  let key = val;
  let value = list[val];
  console.log(`${key} : ${value}`);
});

// Returns:
// "key : value"
// "name : lauren";
// "email : [email protected]"
// "age : 30"
for (var property in object) {
  if (object.hasOwnProperty(property)) {
    // Do things here
  }
}
arr.forEach(callback(currentValue [, index [, array]])[, thisArg]);let array = ['Item 1', 'Item 2', 'Item 3'];

array.forEach(item => {
	console.log(item); // Logs each 'Item #'
});Add thisvar p = {
    "p1": "value1",
    "p2": "value2",
    "p3": "value3"
};

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        console.log(key + " -> " + p[key]);
    }
}
Source

Also in JavaScript: