for/in Statement: Loop through the properties of an object - Javascript Statement

Javascript examples for Statement:for in

Description

for/in Statement: Loop through the properties of an object

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   www  . ja va  2 s. c o m*/
    var person = {fname:"Mary", lname:"Last", age:25};

    var text = "";
    var x;
    for (x in person) {
        text += person[x] + " ";
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials