Home

function: castArray


castArray(value: *): Array

Casts `value` as an array if it's not one.

Example(s):

castArray(1)
// => [1]

castArray({ 'a': 1 })
// => [{ 'a': 1 }]

castArray('abc')
// => ['abc']

castArray(null)
// => [null]

castArray(undefined)
// => [undefined]

castArray()
// => []

const array = [1, 2, 3]
console.log(castArray(array) === array)
// => true

Params:

Name Type Attribute Description
value The value to inspect.

Returns:

Array

  {
    "comment": "/**\r\n * Casts `value` as an array if it's not one.\r\n *\r\n * @since 4.4.0\r\n * @category Lang\r\n * @param {*} value The value to inspect.\r\n * @returns {Array} Returns the cast array.\r\n * @example\r\n *\r\n * castArray(1)\r\n * // => [1]\r\n *\r\n * castArray({ 'a': 1 })\r\n * // => [{ 'a': 1 }]\r\n *\r\n * castArray('abc')\r\n * // => ['abc']\r\n *\r\n * castArray(null)\r\n * // => [null]\r\n *\r\n * castArray(undefined)\r\n * // => [undefined]\r\n *\r\n * castArray()\r\n * // => []\r\n *\r\n * const array = [1, 2, 3]\r\n * console.log(castArray(array) === array)\r\n * // => true\r\n */",
    "meta": {
        "range": [
            547,
            696
        ],
        "filename": "castArray.js",
        "lineno": 33,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100000375",
            "name": "castArray",
            "type": "FunctionDeclaration",
            "paramnames": [
                "args"
            ]
        },
        "vars": {
            "value": "castArray~value"
        }
    },
    "description": "Casts `value` as an array if it's not one.",
    "since": "4.4.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Lang",
            "value": "Lang"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "*"
                ]
            },
            "description": "The value to inspect.",
            "name": "value"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "Array"
                ]
            },
            "description": "Returns the cast array."
        }
    ],
    "examples": [
        "castArray(1)\r// => [1]\r\rcastArray({ 'a': 1 })\r// => [{ 'a': 1 }]\r\rcastArray('abc')\r// => ['abc']\r\rcastArray(null)\r// => [null]\r\rcastArray(undefined)\r// => [undefined]\r\rcastArray()\r// => []\r\rconst array = [1, 2, 3]\rconsole.log(castArray(array) === array)\r// => true"
    ],
    "name": "castArray",
    "longname": "castArray",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000036",
    "___s": true,
    "filepath": "castArray.js"
}