[ES6] ... spread operator

 

 

var parts = ['shoulders', 'knees'];
var lyrics = ['head', ...parts, 'and', 'toes']; // ["head", "shoulders", "knees", "and", "toes"]


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


function myFunction(v, w, x, y, z) {
  console.log(v, w, x, y, z);
}
var args = [0, 1];
myFunction(-1, ...args, 2, ...[3]);]
//-1, 0 , 1, 2, 3

 

posted @ 2015-11-27 03:06  Zhentiw  阅读(311)  评论(0编辑  收藏  举报