Gets the array element index:
IndexOf returns the first index found: can be taken with a start index
LastIndexOf returns the last index found: Available with start index
var animals = new Array ("Dog", "cat" , "seal", "Elephant", "Walrus", "Lion", "cat")
Console.log (Animals.indexof ("cat")); Prints 1
Console.log (Animals.lastindexof ("cat"));//prints 6
Console.log (Animals.indexof ("Cat", 2)); Prints 6
Console.log (Animals.lastindexof ("Cat", 4)); Prints 1
Merging multidimensional arrays into one-dimensional arrays: Concat with Apply method
var fruitarray = [];
Fruitarray[0] = [' Strawberry ', ' orange '];
FRUITARRAY[1] = [' lime ', ' peach ', ' banana '];
FRUITARRAY[2] = [' tangerine ', ' apricot '];
FRUITARRAY[3] = [' Raspberry ', ' kiwi '];
var newarray = Fruitarray.concat.apply ([], Fruitarray);
Console.log (Newarray[5]);
To delete or replace an array element: IndexOf Splice
Splice () method takes three parameters; The first parameter is Required,as
It ' s index where the splicing is to take place; The second,optional parameter is
The number of elements to remove; The third parameter, also optional, is a set of
The replacement elements.
Animals.splice (Animals.indexof ("Walrus"), 1);
Animals.splice (Animals.lastindexof ("Cat"), 1, "monkey");
Console.log (Animals.tostring ());
JavaScript notes--arrays