Removes all elements from `array` that `predicate` returns truthy for and returns an array of the removed elements. The predicate is invoked with three arguments: (value, index, array). **Note:** Unlike `filter`, this method mutates `array`. Use `pull` to pull elements from an array by value.
const array = [1, 2, 3, 4]
const evens = remove(array, n => n % 2 == 0)
console.log(array)
// => [1, 3]
console.log(evens)
// => [2, 4]
Name | Type | Attribute | Description |
---|---|---|---|
array | The array to modify. | ||
predicate | The function invoked per iteration. |
{ "comment": "/**\r\n * Removes all elements from `array` that `predicate` returns truthy for\r\n * and returns an array of the removed elements. The predicate is invoked\r\n * with three arguments: (value, index, array).\r\n *\r\n * **Note:** Unlike `filter`, this method mutates `array`. Use `pull`\r\n * to pull elements from an array by value.\r\n *\r\n * @since 2.0.0\r\n * @category Array\r\n * @param {Array} array The array to modify.\r\n * @param {Function} predicate The function invoked per iteration.\r\n * @returns {Array} Returns the new array of removed elements.\r\n * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, reject, filter\r\n * @example\r\n *\r\n * const array = [1, 2, 3, 4]\r\n * const evens = remove(array, n => n % 2 == 0)\r\n *\r\n * console.log(array)\r\n * // => [1, 3]\r\n *\r\n * console.log(evens)\r\n * // => [2, 4]\r\n */", "meta": { "range": [ 857, 1270 ], "filename": "remove.js", "lineno": 28, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100007644", "name": "remove", "type": "FunctionDeclaration", "paramnames": [ "array", "predicate" ] }, "vars": { "result": "remove~result", "index": "remove~index", "indexes": "remove~indexes", "undefined": null, "value": "remove~value" } }, "description": "Removes all elements from `array` that `predicate` returns truthy for\rand returns an array of the removed elements. The predicate is invoked\rwith three arguments: (value, index, array).\r\r**Note:** Unlike `filter`, this method mutates `array`. Use `pull`\rto pull elements from an array by value.", "since": "2.0.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Array", "value": "Array" } ], "params": [ { "type": { "names": [ "Array" ] }, "description": "The array to modify.", "name": "array" }, { "type": { "names": [ "function" ] }, "description": "The function invoked per iteration.", "name": "predicate" } ], "returns": [ { "type": { "names": [ "Array" ] }, "description": "Returns the new array of removed elements." } ], "see": [ "pull, pullAll, pullAllBy, pullAllWith, pullAt, reject, filter" ], "examples": [ "const array = [1, 2, 3, 4]\rconst evens = remove(array, n => n % 2 == 0)\r\rconsole.log(array)\r// => [1, 3]\r\rconsole.log(evens)\r// => [2, 4]" ], "name": "remove", "longname": "remove", "kind": "function", "scope": "global", "___id": "T000002R000699", "___s": true, "filepath": "remove.js" }