Iterates over elements of `collection`, returning an array of all elements `predicate` returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection). **Note:** Unlike `remove`, this method returns a new array.
const users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false }
]
filter(users, ({ active }) => active)
// => objects for ['barney']
| Name | Type | Attribute | Description |
|---|---|---|---|
| collection | The collection to iterate over. | ||
| predicate | The function invoked per iteration. |
{
"comment": "/**\r\n * Iterates over elements of `collection`, returning an array of all elements\r\n * `predicate` returns truthy for. The predicate is invoked with three\r\n * arguments: (value, index|key, collection).\r\n *\r\n * **Note:** Unlike `remove`, this method returns a new array.\r\n *\r\n * @since 0.1.0\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Function} predicate The function invoked per iteration.\r\n * @returns {Array} Returns the new filtered array.\r\n * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reject\r\n * @example\r\n *\r\n * const users = [\r\n * { 'user': 'barney', 'active': true },\r\n * { 'user': 'fred', 'active': false }\r\n * ]\r\n *\r\n * filter(users, ({ active }) => active)\r\n * // => objects for ['barney']\r\n */",
"meta": {
"range": [
901,
1051
],
"filename": "filter.js",
"lineno": 27,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100002336",
"name": "filter",
"type": "FunctionDeclaration",
"paramnames": [
"collection",
"predicate"
]
},
"vars": {
"func": "filter~func"
}
},
"description": "Iterates over elements of `collection`, returning an array of all elements\r`predicate` returns truthy for. The predicate is invoked with three\rarguments: (value, index|key, collection).\r\r**Note:** Unlike `remove`, this method returns a new array.",
"since": "0.1.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Collection",
"value": "Collection"
}
],
"params": [
{
"type": {
"names": [
"Array",
"Object"
]
},
"description": "The collection to iterate over.",
"name": "collection"
},
{
"type": {
"names": [
"function"
]
},
"description": "The function invoked per iteration.",
"name": "predicate"
}
],
"returns": [
{
"type": {
"names": [
"Array"
]
},
"description": "Returns the new filtered array."
}
],
"see": [
"pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reject"
],
"examples": [
"const users = [\r { 'user': 'barney', 'active': true },\r { 'user': 'fred', 'active': false }\r]\r\rfilter(users, ({ active }) => active)\r// => objects for ['barney']"
],
"name": "filter",
"longname": "filter",
"kind": "function",
"scope": "global",
"___id": "T000002R000257",
"___s": true,
"filepath": "filter.js"
}