What is spread Operator (...) in JavaScript?

JavascriptWeb DevelopmentFront End Technology

With Spread Operator, allow the expression to expand to multiple arguments, elements, variables, etc.

Example

You can try to run the following code to learn how to work with spread operator −

<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>
raja
Published on 19-Jan-2018 05:57:33
Advertisements