数组的下标应该写成:categoryArrayName[1155]这种形式,而不是:categoryArrayName['1155'],然后用for循环就可以输出了:
for(var i=0;i<categoryArrayName.length;i++)
{
document.writeln(categoryArrayName[i]);
}
for(var i=0;i<categoryArrayName.length;i++)
{
document.writeln(categoryArrayName[i]);
}
var categoryArrayName = new Array();
categoryArrayName['1119']='category_1';
categoryArrayName['1122']='category_1_1';
categoryArrayName['1137']='category_1_2';
categoryArrayName['1155']='category_1_3';
for(var key in categoryArrayName){
alert(categoryArrayName[key]);
document.writeln(categoryArrayName[key]);
}
</script>
<Head>
<title>arry</title>
<Meta http-equiv="Content-Type" content = "text/html;charset=EUC-JP">
<script language='javascript'>
function ShowCheckes()
{
var categoryArrayName = new Array(); categoryArrayName['1119']='category_1';
categoryArrayName['1122']='category_1_1';
categoryArrayName['1137']='category_1_2';
categoryArrayName['1155']='category_1_3';
for (loop = 0; loop <categoryArrayName.length; loop++)
{
document.writeln(categoryArrayName[loop]);
} }
</Script>
</head>
<body onload="ShowCheckes();">
</body>
</html>
楼主的 “item” ,是保留字吧!不能做变量名!
var categoryArrayName = new Array();categoryArrayName['1119']='category_1';
categoryArrayName['1122']='category_1_1';
categoryArrayName['1137']='category_1_2';
categoryArrayName['1155']='category_1_3';for (aa in categoryArrayName)
{
alert(aa);
}
</script>