实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>Array Type Example 2</title>
5
    <script type="text/javascript">
6
        
7
        var colors = ["red", "blue", "green"]; //creates an array with three strings
8
        var names = [];                        //creates an empty array
9
        var values = [1,2,];                   //AVOID! Creates an array with 2 or 3 items
10
        var options = [,,,,,];                 //AVOID! creates an array with 5 or 6 items
11
        
12
        alert(colors.length);    //3
13
        alert(names.length);     //0
14
        alert(values.length);    //2 (FF, Safari, Opera) or 3 (IE)
15
        alert(options.length);   //5 (FF, Safari, Opera) or 6 (IE)
16
17
18
    </script>
19
</head>
20
<body>
21
22
</body>
23
</html>