Slice
Revision as of 16:12, 17 March 2020 by 71.226.33.30 (talk) (Created page with "<c>slice</c> returns a subset of a string or list. This is equivalent to using the square-brackets slice operator seq[from:to], but with ordinary function syntax. === Argume...")
slice
returns a subset of a string or list. This is equivalent to using the square-brackets slice operator seq[from:to], but with ordinary
function syntax.
Arguments
Parameter Name | Default Value | Meaning |
---|---|---|
seq | string or list | sequence to get a subsequence of |
from | number, default | 0-based index to the first element to return (if negative, counts from the end) |
to | number, optional | 0-based index of first element to *not* include in the result (if negative, count from the end; if omitted, return the rest of the sequence) |
Example
slice("Hello", -2) // returns "lo"
slice(["a","b","c","d"], 1, 3) // returns ["b", "c"]