Javascript Spread Operator allows splitting an array to single arguments which are passed to the function as separate arguments. The spread operator takes either an array or an object and expands it into its set of items.

Javascript Spread Operator

The spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments or elements are expected, or an object expression to be expanded in areas where zero or more key-value pairs are expected.

The syntax for Spread Operator depends on the context you are working on.

Let us see the following example.

For array literals or strings the syntax is following.

[...iterableObject, 19, 20, 21];

For object literals that are new in ECMAScript 2018, the syntax is following.

#javascript #spread syntax #ecmascript

Javascript Spread Operator Example Tutorial
1.55 GEEK