for...in

種類命令
書式
for (変数 in オブジェクト名)
{
処理
}
解説
オブジェクトが持っているプロパティの数だけ繰り返し処理を行います。
サンプルコード
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<style type="text/css"><!--
body { margin:0px; }
form { position:absolute; top:10;left:10px; }
--></style>
<script type="text/javascript"><!--
window.onload = function()
{
myObj = ["AB",12,"CD",34];
for (i in myObj)
{
document.getElementById("txtField").value = i;
}
}
// --></script>
</head>
<body>
<img src="Default.png">
<form>
<input type="text" id="txtField" size=40"><br>
</form>
</body>
</html>
実際のスクリプトをダウンロード