Spread Operator

Bashar Ayyash
1 min readSep 4, 2015

--

This post is part of Starter to ES6

Spread operator (…) spread array to it’s individual items

let arr = [1, 2, 3];
let arr2 = [4, 5, 6];
console.log(arr);//[1, 2, 3]
console.log(…arr);//1 2 3

let arr3 = […arr2, 7, 8, 9];
console.log(arr3);//[4, 5, 6, 7 , 8, 9]

function calculate(a, b, c){ return a + b + c;
}
console.log(calculate(…arr));//6
console.log(calculate(…arr2));//15

This post is part of Starter to ES6

--

--

Bashar Ayyash

Front End Developer, I’m confident that Vue.js is as powerful as React, but way more flexible and a lot easier to learn