主题
castArray
js
_.castArray(value)
如果 value
不是数组,则将其转换为数组。
¥Casts value
as an array if it's not one.
新增于
¥Since
4.4.0
参数
¥Arguments
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