javascript 方括号的用法
<script type= "text/javascript " >
var obj = [{tmp: "test1 ", tmp1: "test2 "},{tmp: "test3 ", tmp1: "test4 "}];
alert(obj.length);
for(var i = 0 ; i < obj.length ; i++ )
{
alert(obj[i].tmp);
alert(obj[i].tmp1);
}
</script>
请问只是什么用法
------解决方案--------------------[]:数组
{}: 对象
var obj = [{tmp: "test1 ", tmp1: "test2 "},{tmp: "test3 ", tmp1: "test4 "}];
相当于
var obj = new array();
obj[0] = {tmp: "test1 ", tmp1: "test2 "}
obj[1] = {tmp: "test3 ", tmp1: "test4 "}]