mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Bump to v3.0.0.
This commit is contained in:
29
lang/toArray.js
Normal file
29
lang/toArray.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import arrayCopy from '../internal/arrayCopy';
|
||||
import isLength from '../internal/isLength';
|
||||
import values from '../object/values';
|
||||
|
||||
/**
|
||||
* Converts `value` to an array.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to convert.
|
||||
* @returns {Array} Returns the converted array.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
|
||||
* // => [2, 3]
|
||||
*/
|
||||
function toArray(value) {
|
||||
var length = value ? value.length : 0;
|
||||
if (!isLength(length)) {
|
||||
return values(value);
|
||||
}
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
return arrayCopy(value);
|
||||
}
|
||||
|
||||
export default toArray;
|
||||
Reference in New Issue
Block a user