Spread Operator in ECMAScript

Create new Javascript file named demo1.js. This file contains code demo as below:

let cde = ['c', 'd', 'e'];
let scale = ['a', 'b', ...cde, 'f', 'g'];
console.log(scale);

Use node demo1.js statement run code demo

[ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ]




Create new Javascript file named demo2.js. This file contains code demo as below:

const android = ['galaxy s7', 'nokia 1020', 'xiaomi mi5'];
const iphone = ['iphone 7 ', 'iphone8', 'iphone9'];
const phones = [...android, ...iphone, 'nokia phone 100'];
console.log(phones);

Use node demo2.js statement run code demo

[ 'galaxy s7',
  'nokia 1020',
  'xiaomi mi5',
  'iphone 7 ',
  'iphone8',
  'iphone9',
  'nokia phone 100' ]