Tuesday, November 10, 2015

Overview

The spread operator [0, ...a, 5, 6] where a = [1, 2, 3, 4] allows you to spread the contents of a to spread the contents of a to form the new array [0, 1, 2, 3, 4, 5, 6]. You can find out more about it here. This post will have several examples. Here’s another cool website to see other EcmaScript 6 features.

Examples

1
2
3
4
5
6
function aFunction(x, y, z) {
    console.log(`${x} ${y} ${z}`); // "0 1 2"
}

var myList = [0, 1, 2];
aFunction(...args);
1
2
3
var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
arr1.push(...arr2); // [0, 1, 2, 3, 4, 5]

Random Posts