File: slices.md

package info (click to toggle)
coffeescript 1.12.8~dfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,748 kB
  • sloc: javascript: 815; makefile: 57; xml: 9; sh: 6
file content (15 lines) | stat: -rw-r--r-- 619 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## Array Slicing and Splicing with Ranges

Ranges can also be used to extract slices of arrays. With two dots (`3..6`), the range is inclusive (`3, 4, 5, 6`); with three dots (`3...6`), the range excludes the end (`3, 4, 5`). Slices indices have useful defaults. An omitted first index defaults to zero and an omitted second index defaults to the size of the array.

```
codeFor('slices', 'middle')
```

The same syntax can be used with assignment to replace a segment of an array with new values, splicing it.

```
codeFor('splices', 'numbers')
```

Note that JavaScript strings are immutable, and can’t be spliced.