Skip to content

Commit e993e45

Browse files
committed
Merge pull request coffeescript-cookbook#55 from brycec/master
Add a splat technique to concatenating arrays
2 parents 86e4b86 + 82343e6 commit e993e45

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

chapters/arrays/concatenating-arrays.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ array1
4646
# => [1, 2, 3, 4, 5, 6]
4747
{% endhighlight %}
4848

49+
Alternatively, we can pass a CoffeeScript splat (`array2...`) directly into `push()`, avoiding the Array prototype.
50+
51+
{% highlight coffeescript %}
52+
array1 = [1, 2, 3]
53+
array2 = [4, 5, 6]
54+
array1.push array2...
55+
array1
56+
# => [1, 2, 3, 4, 5, 6]
57+
{% endhighlight %}
58+
4959
## Discussion
5060

5161
CoffeeScript lacks a special syntax for joining arrays, but `concat()` and `push()` are standard JavaScript methods.

0 commit comments

Comments
 (0)