Saturday, August 22, 2015

How to Loop through JavaScript object literal

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js object </title>
</head>
<body>

<script>
    std_obj = {
        name : "polo",
        profession : "Student",
        department : "Marketing",
        roll : 51,
        university : 'National University'
    };
    var result = "";
    for (var k in std_obj){
       result = result + k + " : " + std_obj[k] + "<br>";
    }
    document.write(result);
</script>
</body>
</html>

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }