JavaScript support in IE9 is designed to support that latest JavaScript standard,
ECMAScript 5. ECMAScript 5 adds nine new methods for searching and manipulating
array contents. These methods all perform operations that previously would have
required explicit coding of iterative loops. This demo allows you to experiment
with these new methods.
To use it, just choose a method from the drop-down menu in the left column. You
will see a description of the method. In the right column, you may then select the
array object that the method will operate upon. You may also set the argument values
that will be passed to the method. Arguments that are functions are selected from
a set of available functions using radio buttons. Argument values that are not functions
can be entered as numeric literals, string literals delimited with double quote
characters, or the special values: true, false, null,
undefined, Infinity, or NaN. When you click
the Call the method button, the method will be called and the return value
of the call will be displayed
Choose a Method
array1.indexOf(searchElement [, startIndex])
Search the array for the first occurrence of searchElement. Return its index position or -1 if not found.
The search normally starts with the first element of the array. The optional startIndex argument can be used to specify a different starting index for the search. Negative values are positions relative to the end of the array.
array1.lastIndexOf(searchElement [, startIndex])
Search the array for the last occurrence of searchElement. Return its index position or -1 if not found.
The search normally starts with the last element of the array and proceeds towards the first element. The optional startIndex argument can be used to specify a different starting index for the search. Negative values are positions relative to the end of the array.
array1.some(callbackfn [, thisArg])
The callbackfn is called successively on each element of the array, starting with the first element. The some method returns true as soon as a call to the callbackfn function returns a true value; otherwise it returns false if all calls to callbackfn returned a false value. If the array has no elements, the some method returns false.
The signature of a callbackfn function is function (value[,index [,array]])
Where value is the value of an array element, index is the array index of the element, and array is the array object.
The optional thisArg is used to specify a value that is passed to the callbackfn as its this value. thisArg is not used in these examples.
array1.every(callbackfn [, thisArg])
The callbackfn is called successively on each element of the array, starting with the first element. The every method returns false as soon as a call to the callbackfn function returns a false value; otherwise it returns true if all calls to callbackfn returned a true value. If the array has no elements, the every method returns true.
The signature of a callbackfn function is function (value[,index [,array]])
Where value is the value of an array element, index is the array index of the element, and array is the array object.
The optional thisArg is used to specify a value that is passed to the callbackfn as its this value. thisArg is not used in these examples.
array1.forEach(callbackfn [, thisArg])
The callbackfn is called successively on each element of the array, starting with the first element. The forEach method always returns undefined. forEach does not directly modify the array but the callbackfn function may modify it.
The signature of a callbackfn function is function (value[,index [,array]])
Where value is the value of an array element, index is the array index of the element, and array is the array object.
The optional thisArg is used to specify a value that is passed to the callbackfn as its this value. thisArg is not used in these examples.
array1.map(callbackfn[,thisArg])
The map method transforms the elements of an array by calling the callbackfn for each array element and collecting the results of those calls into a new Array.
The map method always returns a new Array whose length is the same as the original array.
The callbackfn is called successively on each element of the original array, starting with the first element and the result of each call is used to populate the corresponding element of the new Array.
map does not directly modify the original array but the callbackfn function may modify it.
The signature of a callbackfn function is function (value[,index [,array]])
Where value is the value of an array element, index is the array index of the element, and array is the array object.
The optional thisArg is used to specify a value that is passed to the callbackfn as its this value. thisArg is not used in these examples.
array1.filter(callbackfn [, thisArg])
The filter method creates a new Array containing selected elements of an original array.
Elements are selected by calling the callbackfn for each original array element. The element values, for which callbackfn returns a true value, are collected into the new Array.
The filter method always returns a new Array but its length will be 0 if no elements are selected from the original array.
The callbackfn is called successively on each element of the original array, starting with the first element.
filter does not directly modify the original array but the callbackfn function may modify it.
The signature of a callbackfn function is function (value [,index[,array]])
Where value is the value of an array element, index is the array index of the element, and array is the array object.
The optional thisArg is used to specify a value that is passed to the callbackfn as its this value. thisArg is not used in these examples.
array1.reduce(callbackfn [, initialValue])
The reduce method accumulates a result by applying a function to the individual elements of an array. Each call to the function is passed the result of the previous call and the result of the final call is the value returned by the reduce method.
The signature of a callbackfn function is function (previousValue, value [, index[, array]])
Where previousValue is either an initial value or the value returned from the previous call of callbackfn, value is the value of an array element, index is the array index of the element, and array is the array object.
The callbackfn is called successively on each element of the array, starting with the first element. reduce does not directly modify the array but the callbackfn function may modify it.
If the optional initialValue is present, its value is used as the previousValue argument to the first call to callbackfn. If initialValue is not present the value of the first array element is used as the first previous value and callbackfn is not called on that element.
array1.reduceRight(callbackfn [, initialValue])
The reduceRight method accumulates a result by applying a function to the individual elements of an array in reverse order. Each call to the function is passed the result of the previous call and the result of the final call is the value returned by the reduceRight method.
The signature of a callbackfn function is function (previousValue, value[, index[, array]])
Where previousValue is either an initial value or the value returned from the previous call of callbackfn, value is the value of an array element, index is the array index of the element, and array is the array object.
The callbackfn is called successively in descending index order on each element of the array, starting with the last element. reduceRight does not directly modify the array but the callbackfn function may modify it.
If the optional initialValue is present, its value is used as the previousValue argument to the first call to callbackfn. If initialValue is not present the value of the last array element is used as the first previous value and callbackfn is not called on that element.