isArray.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var getNative = require('../internal/getNative'),
  2. isLength = require('../internal/isLength'),
  3. isObjectLike = require('../internal/isObjectLike');
  4. /** `Object#toString` result references. */
  5. var arrayTag = '[object Array]';
  6. /** Used for native method references. */
  7. var objectProto = Object.prototype;
  8. /**
  9. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10. * of values.
  11. */
  12. var objToString = objectProto.toString;
  13. /* Native method references for those with the same name as other `lodash` methods. */
  14. var nativeIsArray = getNative(Array, 'isArray');
  15. /**
  16. * Checks if `value` is classified as an `Array` object.
  17. *
  18. * @static
  19. * @memberOf _
  20. * @category Lang
  21. * @param {*} value The value to check.
  22. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  23. * @example
  24. *
  25. * _.isArray([1, 2, 3]);
  26. * // => true
  27. *
  28. * _.isArray(function() { return arguments; }());
  29. * // => false
  30. */
  31. var isArray = nativeIsArray || function(value) {
  32. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  33. };
  34. module.exports = isArray;