NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
* [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); ~~~