javascript 循环

<html>

<head>

<script>

window.onload=function(){

var myobj = new Object();

myobj.color = 'red';

myobj.name = 'hsin';

myobj.nation = 'taiwan';

var myarr = new Array('blue','joe','taiwan');

//使用for(var key in arr)的方式

var content='';

for(var key in myobj){

    content += key+' : '+myobj[key]+'<br />';

}

for(var key in myarr){

    content += key+' : '+myarr[key]+'<br />';

}

document.getElementById('content_box').innerHTML = content;

}

</script>

</head>

<body>

<div id="content_box">

</div>

</body>

</html>


你可能感兴趣的:(javascript 循环)