_.clone(value, [isDeep], [customizer], [thisArg])

Creates a clone of value. If isDeep is true nested objects are cloned, otherwise they are assigned by reference. If customizer is provided it’s invoked to produce the cloned values. If customizer returns undefined cloning is handled by the method instead. The customizer is bound to thisArg and invoked with up to three argument; (value [, index|key, object]).

Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments objects and objects created by constructors other than Object are cloned to plain Object objects. An empty object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps.

Arguments

  1. value (*): The value to clone.
  2. [isDeep] (boolean): Specify a deep clone.
  3. [customizer] (Function): The function to customize cloning values.
  4. [thisArg] (*): The this binding of customizer.

Returns

(*): Returns the cloned value.

Example

  1. var users = [
  2. { 'user': 'barney' },
  3. { 'user': 'fred' }
  4. ];
  5. var shallow = _.clone(users);
  6. shallow[0] === users[0];
  7. // => true
  8. var deep = _.clone(users, true);
  9. deep[0] === users[0];
  10. // => false
  11. // using a customizer callback
  12. var el = _.clone(document.body, function(value) {
  13. if (_.isElement(value)) {
  14. return value.cloneNode(false);
  15. }
  16. });
  17. el === document.body
  18. // => false
  19. el.nodeName
  20. // => BODY
  21. el.childNodes.length;
  22. // => 0

_.cloneDeep(value, [customizer], [thisArg])

Creates a deep clone of value. If customizer is provided it’s invoked to produce the cloned values. If customizer returns undefined cloning is handled by the method instead. The customizer is bound to thisArg and invoked with up to three argument; (value [, index|key, object]).

Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments objects and objects created by constructors other than Object are cloned to plain Object objects. An empty object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps.

Arguments

  1. value (*): The value to deep clone.
  2. [customizer] (Function): The function to customize cloning values.
  3. [thisArg] (*): The this binding of customizer.

Returns

(*): Returns the deep cloned value.

Example

  1. var users = [
  2. { 'user': 'barney' },
  3. { 'user': 'fred' }
  4. ];
  5. var deep = _.cloneDeep(users);
  6. deep[0] === users[0];
  7. // => false
  8. // using a customizer callback
  9. var el = _.cloneDeep(document.body, function(value) {
  10. if (_.isElement(value)) {
  11. return value.cloneNode(true);
  12. }
  13. });
  14. el === document.body
  15. // => false
  16. el.nodeName
  17. // => BODY
  18. el.childNodes.length;
  19. // => 20

_.gt(value, other)

Checks if value is greater than other.

Arguments

  1. value (*): The value to compare.
  2. other (*): The other value to compare.

Returns

(boolean): Returns true if value is greater than other, else false.

Example

  1. _.gt(3, 1);
  2. // => true
  3. _.gt(3, 3);
  4. // => false
  5. _.gt(1, 3);
  6. // => false

_.gte(value, other)

Checks if value is greater than or equal to other.

Arguments

  1. value (*): The value to compare.
  2. other (*): The other value to compare.

Returns

(boolean): Returns true if value is greater than or equal to other, else false.

Example

  1. _.gte(3, 1);
  2. // => true
  3. _.gte(3, 3);
  4. // => true
  5. _.gte(1, 3);
  6. // => false

_.isArguments(value)

Checks if value is classified as an arguments object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isArguments(function() { return arguments; }());
  2. // => true
  3. _.isArguments([1, 2, 3]);
  4. // => false

_.isArray(value)

Checks if value is classified as an Array object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isArray([1, 2, 3]);
  2. // => true
  3. _.isArray(function() { return arguments; }());
  4. // => false

_.isBoolean(value)

Checks if value is classified as a boolean primitive or object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isBoolean(false);
  2. // => true
  3. _.isBoolean(null);
  4. // => false

_.isDate(value)

Checks if value is classified as a Date object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isDate(new Date);
  2. // => true
  3. _.isDate('Mon April 23 2012');
  4. // => false

_.isElement(value)

Checks if value is a DOM element.

Arguments

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

Returns

(boolean): Returns true if value is a DOM element, else false.

Example

  1. _.isElement(document.body);
  2. // => true
  3. _.isElement('<body>');
  4. // => false

_.isEmpty(value)

Checks if value is empty. A value is considered empty unless it’s an arguments object, array, string, or jQuery-like collection with a length greater than 0 or an object with own enumerable properties.

Arguments

  1. value (Array|Object|string): The value to inspect.

Returns

(boolean): Returns true if value is empty, else false.

Example

  1. _.isEmpty(null);
  2. // => true
  3. _.isEmpty(true);
  4. // => true
  5. _.isEmpty(1);
  6. // => true
  7. _.isEmpty([1, 2, 3]);
  8. // => false
  9. _.isEmpty({ 'a': 1 });
  10. // => false

_.isEqual(value, other, [customizer], [thisArg])

Performs a deep comparison between two values to determine if they are equivalent. If customizer is provided it’s invoked to compare values. If customizer returns undefined comparisons are handled by the method instead. The customizer is bound to thisArg and invoked with up to three arguments: (value, other [, index|key]).

Note: This method supports comparing arrays, booleans, Date objects, numbers, Object objects, regexes, and strings. Objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are not supported. Provide a customizer function to extend support for comparing other values.

Aliases

_.eq

Arguments

  1. value (*): The value to compare.
  2. other (*): The other value to compare.
  3. [customizer] (Function): The function to customize value comparisons.
  4. [thisArg] (*): The this binding of customizer.

Returns

(boolean): Returns true if the values are equivalent, else false.

Example

  1. var object = { 'user': 'fred' };
  2. var other = { 'user': 'fred' };
  3. object == other;
  4. // => false
  5. _.isEqual(object, other);
  6. // => true
  7. // using a customizer callback
  8. var array = ['hello', 'goodbye'];
  9. var other = ['hi', 'goodbye'];
  10. _.isEqual(array, other, function(value, other) {
  11. if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
  12. return true;
  13. }
  14. });
  15. // => true

_.isError(value)

Checks if value is an Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, or URIError object.

Arguments

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

Returns

(boolean): Returns true if value is an error object, else false.

Example

  1. _.isError(new Error);
  2. // => true
  3. _.isError(Error);
  4. // => false

_.isFinite(value)

Checks if value is a finite primitive number.

Note: This method is based on Number.isFinite.

Arguments

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

Returns

(boolean): Returns true if value is a finite number, else false.

Example

  1. _.isFinite(10);
  2. // => true
  3. _.isFinite('10');
  4. // => false
  5. _.isFinite(true);
  6. // => false
  7. _.isFinite(Object(10));
  8. // => false
  9. _.isFinite(Infinity);
  10. // => false

_.isFunction(value)

Checks if value is classified as a Function object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isFunction(_);
  2. // => true
  3. _.isFunction(/abc/);
  4. // => false

_.isMatch(object, source, [customizer], [thisArg])

Performs a deep comparison between object and source to determine if object contains equivalent property values. If customizer is provided it’s invoked to compare values. If customizer returns undefined comparisons are handled by the method instead. The customizer is bound to thisArg and invoked with three arguments: (value, other, index|key).

Note: This method supports comparing properties of arrays, booleans, Date objects, numbers, Object objects, regexes, and strings. Functions and DOM nodes are not supported. Provide a customizer function to extend support for comparing other values.

Arguments

  1. object (Object): The object to inspect.
  2. source (Object): The object of property values to match.
  3. [customizer] (Function): The function to customize value comparisons.
  4. [thisArg] (*): The this binding of customizer.

Returns

(boolean): Returns true if object is a match, else false.

Example

  1. var object = { 'user': 'fred', 'age': 40 };
  2. _.isMatch(object, { 'age': 40 });
  3. // => true
  4. _.isMatch(object, { 'age': 36 });
  5. // => false
  6. // using a customizer callback
  7. var object = { 'greeting': 'hello' };
  8. var source = { 'greeting': 'hi' };
  9. _.isMatch(object, source, function(value, other) {
  10. return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  11. });
  12. // => true

_.isNaN(value)

Checks if value is NaN.

Note: This method is not the same as isNaN which returns true for undefined and other non-numeric values.

Arguments

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

Returns

(boolean): Returns true if value is NaN, else false.

Example

  1. _.isNaN(NaN);
  2. // => true
  3. _.isNaN(new Number(NaN));
  4. // => true
  5. isNaN(undefined);
  6. // => true
  7. _.isNaN(undefined);
  8. // => false

_.isNative(value)

Checks if value is a native function.

Arguments

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

Returns

(boolean): Returns true if value is a native function, else false.

Example

  1. _.isNative(Array.prototype.push);
  2. // => true
  3. _.isNative(_);
  4. // => false

_.isNull(value)

Checks if value is null.

Arguments

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

Returns

(boolean): Returns true if value is null, else false.

Example

  1. _.isNull(null);
  2. // => true
  3. _.isNull(void 0);
  4. // => false

_.isNumber(value)

Checks if value is classified as a Number primitive or object.

Note: To exclude Infinity, -Infinity, and NaN, which are classified as numbers, use the _.isFinite method.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isNumber(8.4);
  2. // => true
  3. _.isNumber(NaN);
  4. // => true
  5. _.isNumber('8.4');
  6. // => false

_.isObject(value)

Checks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))

Arguments

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

Returns

(boolean): Returns true if value is an object, else false.

Example

  1. _.isObject({});
  2. // => true
  3. _.isObject([1, 2, 3]);
  4. // => true
  5. _.isObject(1);
  6. // => false

_.isPlainObject(value)

Checks if value is a plain object, that is, an object created by the Object constructor or one with a [[Prototype]] of null.

Note: This method assumes objects created by the Object constructor have no inherited enumerable properties.

Arguments

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

Returns

(boolean): Returns true if value is a plain object, else false.

Example

  1. function Foo() {
  2. this.a = 1;
  3. }
  4. _.isPlainObject(new Foo);
  5. // => false
  6. _.isPlainObject([1, 2, 3]);
  7. // => false
  8. _.isPlainObject({ 'x': 0, 'y': 0 });
  9. // => true
  10. _.isPlainObject(Object.create(null));
  11. // => true

_.isRegExp(value)

Checks if value is classified as a RegExp object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isRegExp(/abc/);
  2. // => true
  3. _.isRegExp('/abc/');
  4. // => false

_.isString(value)

Checks if value is classified as a String primitive or object.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isString('abc');
  2. // => true
  3. _.isString(1);
  4. // => false

_.isTypedArray(value)

Checks if value is classified as a typed array.

Arguments

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

Returns

(boolean): Returns true if value is correctly classified, else false.

Example

  1. _.isTypedArray(new Uint8Array);
  2. // => true
  3. _.isTypedArray([]);
  4. // => false

_.isUndefined(value)

Checks if value is undefined.

Arguments

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

Returns

(boolean): Returns true if value is undefined, else false.

Example

  1. _.isUndefined(void 0);
  2. // => true
  3. _.isUndefined(null);
  4. // => false

_.lt(value, other)

Checks if value is less than other.

Arguments

  1. value (*): The value to compare.
  2. other (*): The other value to compare.

Returns

(boolean): Returns true if value is less than other, else false.

Example

  1. _.lt(1, 3);
  2. // => true
  3. _.lt(3, 3);
  4. // => false
  5. _.lt(3, 1);
  6. // => false

_.lte(value, other)

Checks if value is less than or equal to other.

Arguments

  1. value (*): The value to compare.
  2. other (*): The other value to compare.

Returns

(boolean): Returns true if value is less than or equal to other, else false.

Example

  1. _.lte(1, 3);
  2. // => true
  3. _.lte(3, 3);
  4. // => true
  5. _.lte(3, 1);
  6. // => false

_.toArray(value)

Converts value to an array.

Arguments

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

Returns

(Array): Returns the converted array.

Example

  1. (function() {
  2. return _.toArray(arguments).slice(1);
  3. }(1, 2, 3));
  4. // => [2, 3]

_.toPlainObject(value)

Converts value to a plain object flattening inherited enumerable properties of value to own properties of the plain object.

Arguments

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

Returns

(Object): Returns the converted plain object.

Example

  1. function Foo() {
  2. this.b = 2;
  3. }
  4. Foo.prototype.c = 3;
  5. _.assign({ 'a': 1 }, new Foo);
  6. // => { 'a': 1, 'b': 2 }
  7. _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  8. // => { 'a': 1, 'b': 2, 'c': 3 }