Function Namespace Pot.filter
Defined in: <potlite.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Pot.filter(object, callback, (context))
Creates a new object with all elements that
pass the test implemented by the provided function.
|
Function Namespace Detail
Pot.filter(object, callback, (context))
Creates a new object with all elements that
pass the test implemented by the provided function.
This method like Array.prototype.filter
function isBigEnough(value, index, array) {
return (value >= 10);
}
var filtered = Pot.filter([12, 5, 8, 130, 44], isBigEnough);
debug(filtered);
// @results [12, 130, 44]
function isBigEnough(value, key, object) {
return (value >= 10);
}
var object = {a: 1, b: 20, c: 7, d: 5, e: 27, f: 99};
var result = Pot.filter(object, isBigEnough);
debug(result);
// @results {b: 20, e: 27, f: 99}
- Parameters:
- {Array|Object|*} object
- A target object.
- {Function} callback
- A callback function.
- {*} (context)
- (Optional) Object to use as `this` when executing callback.
- Returns:
- {*} Return the result of each callbacks.