DEV Community

Discussion on: Understanding Rest Parameter Syntax

Collapse
 
laurieontech profile image
Laurie

Probably my most common use case is merging an array or object into something I'm defining. Like so:

const arr = [1,2,3,4]

const numbers = [...arr, 6,7,10]
Collapse
 
ulitroyo profile image
Uli Troyo

You said that it always creates an array, right? Would the result be [[1,2,3,4], 6,7,10]?

...Oh, nevermind, just tried it in the console! It flattens it; that makes a lot of sense!

Thread Thread
 
laurieontech profile image
Laurie

Yup! Check out this post if you want that example specifically. It's essentially grabbing each element in the array and dropping it into a new array structure.