Java Reference
In-Depth Information
Array
The Array object represents an array of variables. It was introduced in JavaScript 1.1. An Array object
can be created with the Array constructor.
var objArray = new Array(10) // an array of 11 elements
var objArray = new Array(“1”, “2”, “4”) // an array of 3 elements
Arrays can also be created using array literal syntax.
var objArray = [];
Literal syntax is the preferred method of creating an array.
Properties
Property
Introduced
Description
constructor
JavaScript 1.1
Used to reference the constructor function for
the object.
length
JavaScript 1.1
Returns the number of elements in the array.
prototype
JavaScript 1.1
Returns the prototype for the object, which
can be used to extend the object's interface.
Methods
Square brackets ( [] ) surrounding a parameter means that parameter is optional.
Method
Introduced
Description
concat(value1 [, value2,…])
JavaScript 1.2
Concatenates two arrays and returns
the new array thus formed.
every(testFn(element, index,
array))
JavaScript 1.6
Iterates over the array, executing
testFn() on every element. Returns
true if all iterations return true .
Otherwise, it returns false .
filter(testFn(element, index,
array))
JavaScript 1.6
Iterates over the array, executing
testFn() on every element. Returns
a new array of elements that pass
testFn().
foreach(fn(element, index,
array))
JavaScript 1.6
Iterates over the array, executing fn()
on every element.
indexOf(element
[, startIndex])
JavaScript 1.6
Returns an index of the specifi ed
element if found, or -1 if not found.
Starts at startIndex if specifi ed.
Search WWH ::




Custom Search