UNPKG

lodash-compat

Version:

The compatibility build of lodash modular utilities.

37 lines (34 loc) 844 B
var arrayCopy = require('../internal/arrayCopy'), getLength = require('../internal/getLength'), isLength = require('../internal/isLength'), isString = require('./isString'), support = require('../support'), values = require('../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 ? getLength(value) : 0; if (!isLength(length)) { return values(value); } if (!length) { return []; } return (support.unindexedChars && isString(value)) ? value.split('') : arrayCopy(value); } module.exports = toArray;