Creates an array with all falsey values removed. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey.
compact([0, 1, false, 2, '', 3])
// => [1, 2, 3]
Name | Type | Attribute | Description |
---|---|---|---|
array | The array to compact. |
{ "comment": "/**\r\n * Creates an array with all falsey values removed. The values `false`, `null`,\r\n * `0`, `\"\"`, `undefined`, and `NaN` are falsey.\r\n *\r\n * @since 0.1.0\r\n * @category Array\r\n * @param {Array} array The array to compact.\r\n * @returns {Array} Returns the new array of filtered values.\r\n * @example\r\n *\r\n * compact([0, 1, false, 2, '', 3])\r\n * // => [1, 2, 3]\r\n */", "meta": { "range": [ 366, 649 ], "filename": "compact.js", "lineno": 14, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100000685", "name": "compact", "type": "FunctionDeclaration", "paramnames": [ "array" ] }, "vars": { "index": "compact~index", "resIndex": "compact~resIndex", "length": "compact~length", "result": "compact~result", "value": "compact~value", "result[undefined]": "compact~result.undefined]" } }, "description": "Creates an array with all falsey values removed. The values `false`, `null`,\r`0`, `\"\"`, `undefined`, and `NaN` are falsey.", "since": "0.1.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Array", "value": "Array" } ], "params": [ { "type": { "names": [ "Array" ] }, "description": "The array to compact.", "name": "array" } ], "returns": [ { "type": { "names": [ "Array" ] }, "description": "Returns the new array of filtered values." } ], "examples": [ "compact([0, 1, false, 2, '', 3])\r// => [1, 2, 3]" ], "name": "compact", "longname": "compact", "kind": "function", "scope": "global", "___id": "T000002R000075", "___s": true, "filepath": "compact.js" }