Computer >> Computer tutorials >  >> Programming >> Javascript

How to use Spread Syntax with arguments in JavaScript functions?


The spread operator will allow you to split an array into single arguments. These arguments are those, which is the function of separate arguments.

Syntax

function myfunction(...iterableObj);

Example

Live Demo

<html>
   <body>
      <script>
         var a, b, c, d, e, f, g;
         a = [10,20];
         b = "rank";
         c = [30, "points"];
         d = "run"

         // concat method.
         e = a.concat(b, c, d);

         // spread operator
         f = [...a, b, ...c, d];
         document.write(e);
         document.write("<br>"+f);
      </script>
   </body>
</html>