...
- Array indices are zero-based.
- The default for the beginning index is 0.
slice(j)
is the same asslice(0,j)
- A reference to an OOB index (less than 0 or greater than the size of the array - 1) will return
null
and raise an error eventreturn an empty array[]
For example:
Code Block | ||||
---|---|---|---|---|
| ||||
a = ["corn","tomato","tomato","tomato","sprouts","lettuce","sprouts"]; c = a.slice(1,4); // c = ["tomato","tomato","tomato","sprouts"] d = a.slice(2); // d = ["corn","tomato","tomato"] g = a.slice(14) // dg = undef[] h = a.slice(0,0); // dh = ["corn"] |
splice()
The
splice()
operator creates a new array that is the result of deleting, inserting, or replacing elements in the target array. The operators takes the following arguments:...