1. 程式人生 > >js new Array創建數組

js new Array創建數組

charset spa console script col clas htm har log

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

//創建一個初識長度為 4 的數組對象 var arr = new Array(4);
//進行賦值,字面量創建的數組對象也可以用此方法創建
  arr[0]="ni";
  arr[1] = "hao"
  arr[2] = "ma"
  arr[3] = "hao

//創建一個長度為5,內容為a b c d p 的數組對象 var arr1
= new Array("a","b","c","d","p"); console.log(arr) console.log(arr1) </script> </body> </html>

js new Array創建數組