Skip to content

castArray

js
_.castArray(value)

如果 value 不是数组,则将其转换为数组。

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

新增于

¥Since

4.4.0

参数

¥Arguments

  1. value (*):要检查的值。

    ¥value ()*: The value to inspect.

返回

¥Returns

(数组):返回强制类型转换数组。

¥(Array): Returns the cast array.

示例

¥Example

js
_.castArray(1);
// => [1]

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

_.castArray('abc');
// => ['abc']

_.castArray(null);
// => [null]

_.castArray(undefined);
// => [undefined]

_.castArray();
// => []

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

Lodash v4.17 中文网 - 粤ICP备13048890号