_.castArray

_.castArray(value)

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

Since

4.4.0

Arguments

  1. value (*): The value to inspect.

Returns

(Array): Returns the cast array.

Example

_.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
doc_Lodash
2016-11-27 16:35:45
Comments
Leave a Comment

Please login to continue.