The Special One




One of the major new feature introduced by ECMA6 is the rest operator. It is denoted by three dots before a variable name. 

It groups the values or parameters, puts them inside an array and assigns this array to the rest variable. It can be used as the last parameter in functions or with array and object destructuring.

Below snippet shows the rest operator in use.

let commonAPIs = ["GlideRecord","GlideAggregate","GlideDateTime","GlideDate"];
let gr, dateAPIs;
[gr, , ...dateAPIs] = commonAPIs;

In this example, we are using the rest operator with array destructuring. Above snippet will assign string "GlideRecord" to the variable gr, skip the second entry i.e. "GlideAggregate" and then create a new array with the last two values and assign this array to the variable dateAPIs. So, dateAPIs variable in this case will contain an array with two entries, GlideDateTime and GlideDate.









Creative Commons License

Comments