for-inループ文を使い、連想配列(簡易オブジェクト)の要素をリスト表示する方法。
サンプル
順序リスト
<script type="text/javascript">
var $obj = {
propA: "値1",
propB: "値2",
propC: "値3"
};
document . write( '<ol>' );
for ( var $prop in $obj ) {
document . write( '<li>' );
document . write( $obj[$prop] );
document . write( '</li>' );
}
document . write( '</ol>' );
</script>
var $obj = {
propA: "値1",
propB: "値2",
propC: "値3"
};
document . write( '<ol>' );
for ( var $prop in $obj ) {
document . write( '<li>' );
document . write( $obj[$prop] );
document . write( '</li>' );
}
document . write( '</ol>' );
</script>
↓↓↓出力結果↓↓↓
順不同リスト
<script type="text/javascript">
var $obj = {
propA: "値1",
propB: "値2",
propC: "値3"
};
document . write( '<ul>' );
for ( var $prop in $obj ) {
document . write( '<li>' );
document . write( $obj[$prop] );
document . write( '</li>' );
}
document . write( '</ul>' );
</script>
var $obj = {
propA: "値1",
propB: "値2",
propC: "値3"
};
document . write( '<ul>' );
for ( var $prop in $obj ) {
document . write( '<li>' );
document . write( $obj[$prop] );
document . write( '</li>' );
}
document . write( '</ul>' );
</script>
↓↓↓出力結果↓↓↓