Friday, May 4, 2018

es6 spead or reset ... , export default {...}

on es6 there is ... symbol,
1) it is transfer an array to and string and the string has been separated by ",";
such as:
var fruit = ["apple", "pear", "kiwifruit"];
console.log(...fruit);

that will be printed as

 apple, pear, kiwifruit;
2) if we are going to extend an array with another array we can do

var fruit =  ["apple", "pear", "kiwifruit"];
var moreFruits = ["pineapple", ...fruit];

the moreFruits is ["pineapple", "apple", "pear", "kiwifruit"];


3) unsure the number of parameters of function:
such as

function add(...vals){
  let sum=0;
  for(let i=0;i    sum+=vals[i];
  }
  return sum;
}

No comments: