For-in loop in JavaScript is used to iterate over the properties of an
object. It can be a great debugging tool if we want to show the contents of
an object. The for-in loop iterates only over those keys of an object which
have their enumerable property set to “true”. The key values in an object
have four attributes (value, writable, enumerable, and configurable).
Enumerable when set to “true” means that we can iterate over that
property.
Syntax
for (key in object) {
}
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var obj = {
firstName : "Yahoo",
lastName : "Baba",
Age : 25,
email : "hello@yahoobaba.net"
};
for(var key in obj){
document.write(key + " : " + obj[key] + "<br>");
}
</script>
</head>
<body>
</body>
</html>