Rest allows a function store multiple objects in a single array. Here is an example…
function animals(…animals) {
animalIds.forEach(animal => console.log(animal));
}
animals(‘gorilla’, ‘koala’, ‘elephant’);
When run, the console would output ‘gorilla’, ‘koala’, ‘elephant’ to the console.
Note: that rest parameters must be the last parameter in the function. This is why it is called “rest”…it is the rest of the parameters.
Happy Coding!
Clay Hess