Skip to content

Instantly share code, notes, and snippets.

@mehdi-farsi
Last active May 15, 2018 01:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehdi-farsi/22b7a3064435c8570d1e185557040f22 to your computer and use it in GitHub Desktop.
Save mehdi-farsi/22b7a3064435c8570d1e185557040f22 to your computer and use it in GitHub Desktop.
Assigning the Rest of an Array to a Variable

When destructuring an array, you can unpack and assign the remaining part of it to a variable using the rest pattern

a = [1, 2, 3]
b, *rest = *a

b    # => 1
rest # => [2, 3]
a    # => [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment