使用数组字面量表示法

2017-06-15 18:33:00
admin
原创
517
<!DOCTYPE html>
<html>
<head>
    <title>Array Type Example 2</title>
    <script type="text/javascript">
        
        var colors = ["red", "blue", "green"]; //creates an array with three strings
        var names = [];                        //creates an empty array
        var values = [1,2,];                   //AVOID! Creates an array with 2 or 3 items
        var options = [,,,,,];                 //AVOID! creates an array with 5 or 6 items
        
        alert(colors.length);    //3
        alert(names.length);     //0
        alert(values.length);    //2 (FF, Safari, Opera) or 3 (IE)
        alert(options.length);   //5 (FF, Safari, Opera) or 6 (IE)


    </script>
</head>
<body>

</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络