* [4.1](https://github.com/yuche/javascript#4.1)?使用字面值創建數組。
~~~
// bad
const items = new Array();
// good
const items = [];
~~~
* [4.2](https://github.com/yuche/javascript#4.2)?向數組添加元素時使用 Arrary#push 替代直接賦值。
~~~
const someStack = [];
// bad
someStack[someStack.length] = 'abracadabra';
// good
someStack.push('abracadabra');
~~~
* [4.3](https://github.com/yuche/javascript#4.3)?使用拓展運算符?`...`?復制數組。
~~~
// bad
const len = items.length;
const itemsCopy = [];
let i;
for (i = 0; i < len; i++) {
itemsCopy[i] = items[i];
}
// good
const itemsCopy = [...items];
~~~
* [4.4](https://github.com/yuche/javascript#4.4)?使用 Array#from 把一個類數組對象轉換成數組。
~~~
const foo = document.querySelectorAll('.foo');
const nodes = Array.from(foo);
~~~
- 關于
- 1. 類型
- 2. 引用
- 3. 對象
- 4. 數組
- 5. 解構
- 6. 字符串
- 7. 函數
- 8. 箭頭函數
- 9. 構造函數
- 10. 模塊
- 11. Iterators & Generators
- 12. 屬性
- 13. 變量
- 14. 提升
- 15. 比較運算符 & 等號
- 16. 代碼塊
- 17. 注釋
- 18. 空白
- 19. 逗號
- 20. 分號
- 21. 類型轉換
- 22. 命名規則
- 23. 存取器
- 24. 事件
- 25. jQuery
- 26. ECMAScript 5 兼容性
- 27. ECMAScript 6 編碼規范
- 28. 測試
- 29. 性能
- 30. 資源
- 31. 使用人群
- 32. 翻譯
- 33. JavaScript 編碼規范說明
- 34. 一起來討論Javascript
- 35. Contributors
- 36. License