Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to Pass Array Elements in Function Calls With the Spread Operator in JavaScript

// When you have a function that takes in a number and you have these numbers as
// elements of an array, You can use the spread operator to pass these elements
// into the function call as arguments using the spread operator

let scores = [12, 33, 6]

const addAll = (a, b, c) => {
    console.log(a + b + c);
};

addAll(...scores); // 51
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Pass #Array #Elements #Function #Calls #With #Spread #Operator #JavaScript
ADD COMMENT
Topic
Name
5+1 =