Table of Contents
Object.entries() returns an array of the key/value pairs of an object (as arrays):
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Iterations</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Object.entries()</h4>
<p id="demo"></p>
<script>
const person = {
firstName: "John",
lastName: "Doe",
age: 30
};
const entries = Object.entries(person);
let text = "";
for (let entry of entries) {
text += entry[0] + ": " + entry[1] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>

Result View Example
Object.values() returns an array of the property values of an object:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Iterations</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Object.values()</h4>
<p id="demo"></p>
<script>
const person = {
firstName: "John",
lastName: "Doe",
age: 30
};
const values = Object.values(person);
document.getElementById("demo").innerHTML = "Values: " + values;
</script>
</body>
</html>

Result View Example
Object.keys() returns an array of the property keys (names) of an object:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Iterations</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Object.keys()</h4>
<p id="demo"></p>
<script>
const person = {
firstName: "John",
lastName: "Doe",
age: 30
};
const keys = Object.keys(person);
let text = "";
for (let key of keys) {
text += key + "<br>";
}
document.getElementById("demo").innerHTML = "Keys:<br>" + text;
</script>
</body>
</html>

Result View Example
The for...in loop iterates over the properties of an object:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Iterations</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>for...in Loop</h4>
<p id="demo"></p>
<script>
const person = {
firstName: "John",
lastName: "Doe",
age: 30
};
let text = "";
for (let key in person) {
text += key + ": " + person[key] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>

Result View Example
Object.groupBy() groups elements of an array by a string value returned from a callback function:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Iterations</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Object.groupBy()</h4>
<p id="demo"></p>
<script>
const fruits = [
{ name: "apple", color: "red" },
{ name: "banana", color: "yellow" },
{ name: "grape", color: "purple" },
{ name: "strawberry", color: "red" }
];
// Group fruits by color
const result = Object.groupBy(fruits, item => item.color);
let text = "";
for (let color in result) {
text += color + ": " + result[color].map(f => f.name).join(", ") + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>

Result View Example
Document in project
You can Download PDF file.