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

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


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>