Layout Options

  • Fixed Header
    Makes the header top fixed, always visible!
  • Fixed Sidebar
    Makes the sidebar left fixed, always visible!
Array Every

Description

The every() method is used run a function on items in the array while that function is returning true. It returns true if the function returns true for every item in the array.

This method has the form:

Array.every(callback[, thisObject])
Parameter Description
callback (required) Specifies the function to test for each element

The callback is invoked with three arguments:
1. the value of the element,
2. the index of the element, and
3. the Array object being traversed
thisObject (optional) Specifies the object to use as this when executing callback

If a this parameter is specified, it will be used as the this for each invocation of the callback. If it is not provided, or is null, the global object associated with callback is used instead.

Note: The specified callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.

Examples

The following example shows the basic use of this method.

<script>
function isInventoryEnough(element, index, array) {
return (element >= 5);
}
var enoughInv1 = [6, 9, 23, 48, 17, 4].every(isInventoryEnough);
document.write("enoughInv1 = " + enoughInv1); document.write("\n");
var enoughInv2= [6, 9, 23, 48, 17, 14].every(isInventoryEnough);
document.write("enoughInv2 = " + enoughInv2); </script>

This produces the following result:

Browser Support

Firefox IE Chrome Opera Safari

Version Information

This form was added in version: 1.6