how to iterate through an object in javascript

JavaScript
// Looping through arrays created from Object.keys
const keys = Object.keys(fruits)
for (const key of keys) {
  console.log(key)
}

// Results:
// apple
// orange
// pear
Object.keys(obj).forEach(function(key) {
  console.log(key, obj[key]);
});for (var prop in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, prop)) {
        // do stuff
    }
}Object.entries(obj).forEach(
    ([key, value]) => console.log(key, value)
);var obj = {
  first: "John",
  last: "Doe"
};

//
//	Visit non-inherited enumerable keys
//
Object.keys(obj).forEach(function(key) {

  console.log(key, obj[key]);

});Object.keys
Object.values
Object.entries
Source

Also in JavaScript: