Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Passing arrays to functions with the spread operator

let numbers = [ 1, 2, 3 ]
let myFunction = (x, y, z) => {
    return x + y + z;
}

// Returns 6
let getCalculation = myFunction(...numbers);
Comment

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: qiankun angular 
Javascript :: nodejs express parse query params boolean 
Javascript :: volta node list 
Javascript :: prevent form submit twice jquery 
Javascript :: class parent and class child 
Javascript :: remove nth character from string javascript 
Javascript :: append different object in object javascript 
Javascript :: Backbone Model Set Can Set Muliple Values At Once 
Javascript :: Add Click events to multiple classes. 
Javascript :: CDNs for arquero 
Javascript :: codigo para salvar javascript 
Javascript :: numberformat chakra 
Javascript :: Listen to custom event in Vue.js 
Javascript :: get a nodes path alias 
Javascript :: nuxtjs update parent parameter 
Javascript :: javascript convert color string to rgb 
Javascript :: React clock via props 
Javascript :: js notimplemented error 
Javascript :: how to create session cookie in node js 
Javascript :: increment number in for loop javascript 
Javascript :: page object 
Javascript :: stack overflow multiselect error react 
Javascript :: sequelzie order by 
Javascript :: how to use handlebars.registerhelper if null 
Javascript :: extract image in p5.js 
Javascript :: draw image inside canvas width 100% 
Javascript :: folder array randomizer 
Javascript :: javascript vuelidate identical passwords only if checkbox is ticked 
Javascript :: angularjs Prevent from getting rendered 
Javascript :: Calling $http.post in batches and chaining promises 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =