1.

How do you use the spread Operator & Spread operators?

Answer»

Using the REST operator we can CALL a function using any number of arguments and can be accessed as an ARRAY. It allows the destruction of an array of objects.

Example of Rest operator in JavaScript

function SUM(...theArgs) {
   return theArgs.reduce((last, now) => {
      return last + now;
   });
}
console.log(sum(1, 2, 3, 4,5)); // expected output 15

 

Speare operator is just the reverse of rest OPERATORS and allows to expand an iterable such as an array expression can be expanded using by dividing the array into individual elements.

For example

let array 1 = [3,4];
let array 2 = [5,6,7];
array= [...array 1,...array 2];
console.log(array); // [ 3, 4, 5,6,7 ]



Discussion

No Comment Found