Array Methods:
For this page, all functions
use the following [array]
, which has been declared globally:
membersDogsDAmour = ["Tyla", "Bam Bam", "Jo Dog", "Steve James"];
- Manipulating
[arrays]
array.push(item1, item2, ..., itemX);
Inserts value at end of [array]
. Alters original [array]
array.pop();
Removes value at end of [array]
. Alters original [array]
and returns a new [array]
array.unshift(item1, item2, ..., itemX);
Inserts value at start of [array]
. Alters original [array]
array.shift();
Removes value at start of [array]
. Alters original [array]
and returns a new [array]
array.fill(value, (start), (end));
Replaces value according to # indices. If no second #, fills to the end of [array]
array.slice((start / -start), (end / -end));
Removes value according to # indices. If no second #, fills to the end of [array]
.
Does not change original [array]
array.splice(index / -index, (howmany), (item1, ....., itemX));
Adds and/or removes value according to # indices. If no second #, fills to the end of [array]
.
Alters original [array]
array.reverse();
Reverses original [array]
array.sort((compareFunction));
Sorts original [array]
(either alphabetically or numerically)
array.concat(array2, array3, ..., arrayX);
Concatenates two [arrays]
. Does not change original
array.copyWithin(target, (start), (end));
Copies from within an [array]
. Changes original
Array.prototype.name=value;
Allows you to add new properties and methods to the Array() object