The for in loop uses the following properties and methods to get the values of all properties in the object

<!DOCTYPE html>
<html>
<body>
<p>Click the button below to loop through the properties of the object "person". </p>
<button onclick="myFunction()">click here</button>
<p id="demo"></p>

<script>
function myFunction()
{
var x;
var txt="";
var person={fname:"Bill",lname:"Gates",age:56};

for (x in person)
{
txt=txt + person[x];
}

document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
</html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325216159&siteId=291194637