[ES6] 13. Using the ES6 spread operator ...
ES6 The 13 ... Using Operator spread
2023-09-14 09:00:55 时间
The spread operator (...) allows you to "explode" an array into its individual elements.
Spreate an array:
console.log([1,2,3]); // [1, 2, 3] console.log(...[1,2,3]); // 1 2 3
Spread out the second array and push that in first array:
let first = [1,2,3]; let second = [4,5,6]; first.push(second); console.log(first); // [1, 2, 3, [4, 5, 6]] first.push(...second); console.log(first); // [1, 2, 3, 4, 5, 6]
Pushing in an array of parameters:
let var1 = [1,2,3]; let var2 = [4,5,6]; function sumUp(a,b,c){ console.log( a+b+c ); } sumUp(...var1); // 6 sumUp(...var2); // 15
相关文章
- es6-Set与Map
- es6零碎记忆
- React+Webpack+ES6 兼容低版本浏览器(IE9)解决方案
- ES5和ES6作用域
- Sublime Es6教程1-环境搭建
- [Javascript] ES6 Class Constructors and the Super Keyword
- [TypeScript] Using ES6 and ESNext with TypeScript
- [ES6] Array -- Destructuring and Rest Parameters && for ..of && Arrat.find()
- [ES6] Spread Operator
- [ES6] 04. The let keyword -- 2 Fiald case
- [ES6] 02. Traceur compiler and Grunt
- es6 javascript的class的静态方法、属性和实例属性
- [Javascript] ES6 Class Constructors and the Super Keyword
- [ES6] Converting an array-like object into an Array with Array.from()
- [ES6] Array.find()
- [AngularJS + Webpack] ES6 with BabelJS
- js es6 标签模板还原字符串
- js es6 Proxy
- js es6 模板字符
- 使用ES6的fetch API读取数据时要注意的一个和cookie相关的坑
- ES6 Fetch API和Cookie相关的知识点
- javascript案例40——tab导航栏(切换、添加、删除、修改)综合案例(es6面向对象、类的使用)
- es6 语法 (Proxy和Reflect 的对比)
- 如何在Pycharm设置ES6语法环境
- 001-es6变量声明、解构赋值、解构赋值主要用途