Login Register Help
API Documentation
Choose a stylesheet:

Functiondojo.filter (returns Array)

dojo.require("dojo._base.array");

This function corresponds to the JavaScript 1.6 Array.filter() method, with one difference: when run over sparse arrays, this implemenation passes the “holes” in the sparse array to the callback function with a value of undefined. JavaScript 1.6’s filter skips the holes in the sparse array. For more details, see: https://developer.mozilla.org/en/CoreJavaScript1.5_Reference/Objects/Array/filter

parametertypedescription
arrArraythe array to iterate over.
callbackFunction|Stringa function that is invoked with three arguments (item, index, array). The return of this function is expected to be a boolean which determines whether the passed-in item will be included in the returned array.
thisObjectObjectOptional. may be used to scope the call to callback

Usage

var foo: Array=dojo.filter(arr: Array, callback: Function|String, thisObject: Object?);

Examples

Example 1

// returns [2, 3, 4]
dojo.filter([1, 2, 3, 4], function(item){ return item>1; });