# Array 數組對象
[TOC]
提供對創建任何數據類型的數組的支持。
## 數組的創建
~~~
<script>
var arr = ['hello','rose','think'];
console.log(arr); // ["hello", "rose", "think"]
var arr = new Array();
arr[0] = 'hello';
arr[1] = 'world';
console.log(arr); // ["hello", "world"]
</script>
~~~
## 數組的訪問
通過制定數組名以及索引號可以訪問某個特定的元素。
>[info]
[0]是數組的第一個元素
[1]是數組的第二個元素
## 數組常用的方法
### concat方法 合并數組
~~~
<script>
var arr_1 = ['hello','world'];
var arr_2 = ['rose','curder'];
var arr_3 = arr_1.concat(arr_2);
console.log(arr_3); // ["hello", "world", "rose", "curder"]
</script>
~~~
### sort方法 數組排序
~~~
<script>
var arr_1 = ['a','c','d','z','e'];
var arr_2 = ['3','5','6','2','1'];
console.log(arr_1.sort()); // ["a", "c", "d", "e", "z"]
console.log(arr_2.sort()); // ["1", "2", "3", "5", "6"]
console.log(arr_2.sort(function(a,b){return b-a;})); // ["6", "5", "3", "2", "1"] 降序排列
</script>
~~~
### push方法 末尾追加元素
~~~
<body>
<script>
var arr_1 = [1,2,3,4];
arr_1.push(5); // 末尾追加
console.log(arr_1); // [1, 2, 3, 4, 5]
</script>
~~~
### reverse方法 數組元素翻轉
~~~
<script>
var arr = ['d','a','c'];
console.log(arr.reverse()); // ["c", "a", "d"]
</script>
~~~
- 空白目錄
- JavaScript保留字
- JS事件
- JS面向對象
- JS內置對象
- 自定義對象
- String 字符串對象
- Date 日期時間對象
- Array 數組對象
- Math 對象
- DOM對象控制HTML
- getElementsByName
- getElementsByTagName
- getAttribute 獲取元素屬性
- setAttribute 設置元素屬性
- childNodes 訪問子節點
- parentNode 訪問父節點
- createElement 創建元素節點
- createTextNode 創建文本節點
- insertBefore 插入節點
- removeChild 刪除節點
- offsetHeight 網頁高度
- scrollHeight 網頁高度
- JS瀏覽器對象
- window對象
- 計時器
- history對象
- location對象
- screen對象
- navigator對象
- 彈出窗口
- cookies