Skip to content

Instantly share code, notes, and snippets.

@soyart
Created June 26, 2021 17:07
Show Gist options
  • Select an option

  • Save soyart/ffd6eba4adec5343843eca3919396fcd to your computer and use it in GitHub Desktop.

Select an option

Save soyart/ffd6eba4adec5343843eca3919396fcd to your computer and use it in GitHub Desktop.
Spread and Rest operator
/* Spread: expands array into elements */
arr = [1, 2, 3];
arr1 = [...arr, 4]; // [1, 2, 3, 4]
/* Rest: condenses elements into array */
function multiply(multiplier, ...args) {
return args.map(num => num * multiplier);
}
multiply(2, 3, 4); // [6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment