Filter items out of an array, by using a filter function.
The specified function will be passed two arguments: The current array item and the index of the item in the array. The function must return 'true' to keep the item in the array, false to remove it.
Arguments:
| array | Array | |
|---|---|---|
| The Array to find items in. | ||
| callback | Function | |
The function to process each item against. The first argument to the function is the list item, and the second argument is the list index. The function should return a Boolean value. Optionally, this argument may be a string rather than a function. If the argument is a string, it is treated as a short "lambda-form" function, with "a" representing the list item and "i" representing the index. For example, "a > 0" may be passed instead of "function(a){ return a > 0; }".
function callback(elementOfArray, indexInArray) {
var shouldKeepIt;
this; // unmapped
return shouldKeepIt;
}
| ||
| invert (Optional) | Boolean | |
| If "invert" is false, or not provided, then the function returns an array consisting of all elements for which "callback" returns true. If "invert" is true, then the function returns an array consisting of all elements for which "callback" returns false. | ||