Passing Arrays as Function Arguments

Samantha Ming
DailyJS
Published in
4 min readFeb 18, 2019

--

If you want to pass an array into a variadic function. You can use ES6 spread to turn that array into a list of arguments. Yay, so much cleaner and no useless null from the old apply way 👏

function sandwich(a, b, c) { 
console.log(a) // '🍞'
console.log(b) // '🥬'
console.log(c) // '🥓'
}
const food = ['🍞', '🥬', '🥓'];// Old way…

--

--

Samantha Ming
DailyJS

Frontend Developer sharing weekly JS, HTML, CSS code tidbits🔥 Discover them all on samanthaming.com 💛