看php, 太随意了:

<?php 

    $a = array();
    $a[0] = 1;
    $a[1] = 2;
    
    print_r($a);
?>
     OK

<?php 
    $a[0] = 1;
    $a[1] = 2;
    
    print_r($a);
?>
     OK


      再看js:

<html>
<body>

<script>
        var myArray = new Array(); 
        myArray[0]="1";
        myArray[1]="2";
        myArray[2]="3";

        alert(myArray[0]);
</script>

</body>
</html>
      OK

<html>
<body>

<script>
        myArray[0]="1";
        myArray[1]="2";
        myArray[2]="3";

        alert(myArray[0]);
</script>

</body>
</html>
       不OK






本文转载:CSDN博客