Learn how you can use JavaScript spread operator on arrays and objects
JavaScript spread operator (...
) is used to expand the values of an iterable ( usually an array or an object) so that you can pass those values as arguments of a function. For example, let’s say you have a function that calculates the sum of three numbers:
function sumThree(a, b, c){
return a+b+c;
}
Next, you want to pass an array of three numbers into the function. You can use the spread operator on the function:
let scores = [7, 9, 7];
let summedNumber = sumThree(...scores);
// The same as sumThree(7, 9, 7);
console.log(summedNumber);
// output is 23
#javascript #es6 #programming #developer #web-development