A quick look at javascript spread operator in ecma6

Our Own Score

Javascript spread operator which has been introduced in ecma6 allows us to expand an expression in place easily. If we want to expand two arrays inside a new array then we can first create that two arrays like so…

const a = [1, 2, 3]
const b = [4, 5, 6]

Next we can expand the elements of the above arrays in a new array like this…

const c = [...a,...b]

which will result in a new array like this

const c = [1,2,3,4,5,6]

This is very easy as compared to previously which we need to use various insert methods to create a new array which consists of two arrays above.

0

Leave a Reply

avatar
  Subscribe  
Notify of