More array methods
The following is an incomplete list of other array methods, none of which mutateThe process of changing data. the array.
Name | Meaning |
---|---|
.concat(arrayOne, arrayTwo) |
returns a new array formed by concatenatingTo make a new one by gluing together two. arrayOne and arrayTwo to the array; one or more arguments can be used |
.toString() |
returns a string formed by concatenating all the items, using the string "," between each consecutive pair |
.join(joiner) |
returns a string formed by concatenating all the items, using the string joiner between each consecutive pair |
.indexOf(item) |
returns the index of the leftmost occurrence of the item |
.lastIndexOf(item) |
returns the index of the rightmost occurrence of the item |
.slice(start, end) |
returns a new array formed including elements with index start up through end - 1 |
.slice(start) |
returns a new array formed including elements with index start up through the end of the original array |
Note:
Hints:
- undefined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
var animals = ["ape", "dog", "bee", "cat", "dog", "eel"];
var vegetables = ["carrot", "onion", "bean"];
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX