- _.clone(value, [isDeep], [customizer], [thisArg])
- _.cloneDeep(value, [customizer], [thisArg])
- _.gt(value, other)
- _.gte(value, other)
- _.isArguments(value)
- _.isArray(value)
- _.isBoolean(value)
- _.isDate(value)
- _.isElement(value)
- _.isEmpty(value)
- _.isEqual(value, other, [customizer], [thisArg])
- _.isError(value)
- _.isFinite(value)
- _.isFunction(value)
- _.isMatch(object, source, [customizer], [thisArg])
- _.isNaN(value)
- _.isNative(value)
- _.isNull(value)
- _.isNumber(value)
- _.isObject(value)
- _.isPlainObject(value)
- _.isRegExp(value)
- _.isString(value)
- _.isTypedArray(value)
- _.isUndefined(value)
- _.lt(value, other)
- _.lte(value, other)
- _.toArray(value)
- _.toPlainObject(value)
_.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
value
(*): The value to clone.[isDeep]
(boolean): Specify a deep clone.[customizer]
(Function): The function to customize cloning values.[thisArg]
(*): Thethis
binding ofcustomizer
.
Returns
(*): Returns the cloned value.
Example
var users = [
{ 'user': 'barney' },
{ 'user': 'fred' }
];
var shallow = _.clone(users);
shallow[0] === users[0];
// => true
var deep = _.clone(users, true);
deep[0] === users[0];
// => false
// using a customizer callback
var el = _.clone(document.body, function(value) {
if (_.isElement(value)) {
return value.cloneNode(false);
}
});
el === document.body
// => false
el.nodeName
// => BODY
el.childNodes.length;
// => 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
value
(*): The value to deep clone.[customizer]
(Function): The function to customize cloning values.[thisArg]
(*): Thethis
binding ofcustomizer
.
Returns
(*): Returns the deep cloned value.
Example
var users = [
{ 'user': 'barney' },
{ 'user': 'fred' }
];
var deep = _.cloneDeep(users);
deep[0] === users[0];
// => false
// using a customizer callback
var el = _.cloneDeep(document.body, function(value) {
if (_.isElement(value)) {
return value.cloneNode(true);
}
});
el === document.body
// => false
el.nodeName
// => BODY
el.childNodes.length;
// => 20
_.gt(value, other)
Checks if value
is greater than other
.
Arguments
value
(*): The value to compare.other
(*): The other value to compare.
Returns
(boolean): Returns true
if value
is greater than other
, else false
.
Example
_.gt(3, 1);
// => true
_.gt(3, 3);
// => false
_.gt(1, 3);
// => false
_.gte(value, other)
Checks if value
is greater than or equal to other
.
Arguments
value
(*): The value to compare.other
(*): The other value to compare.
Returns
(boolean): Returns true
if value
is greater than or equal to other
, else false
.
Example
_.gte(3, 1);
// => true
_.gte(3, 3);
// => true
_.gte(1, 3);
// => false
_.isArguments(value)
Checks if value
is classified as an arguments
object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isArguments(function() { return arguments; }());
// => true
_.isArguments([1, 2, 3]);
// => false
_.isArray(value)
Checks if value
is classified as an Array
object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isArray([1, 2, 3]);
// => true
_.isArray(function() { return arguments; }());
// => false
_.isBoolean(value)
Checks if value
is classified as a boolean primitive or object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isBoolean(false);
// => true
_.isBoolean(null);
// => false
_.isDate(value)
Checks if value
is classified as a Date
object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isDate(new Date);
// => true
_.isDate('Mon April 23 2012');
// => false
_.isElement(value)
Checks if value
is a DOM element.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is a DOM element, else false
.
Example
_.isElement(document.body);
// => true
_.isElement('<body>');
// => 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
value
(Array|Object|string): The value to inspect.
Returns
(boolean): Returns true
if value
is empty, else false
.
Example
_.isEmpty(null);
// => true
_.isEmpty(true);
// => true
_.isEmpty(1);
// => true
_.isEmpty([1, 2, 3]);
// => false
_.isEmpty({ 'a': 1 });
// => 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
value
(*): The value to compare.other
(*): The other value to compare.[customizer]
(Function): The function to customize value comparisons.[thisArg]
(*): Thethis
binding ofcustomizer
.
Returns
(boolean): Returns true
if the values are equivalent, else false
.
Example
var object = { 'user': 'fred' };
var other = { 'user': 'fred' };
object == other;
// => false
_.isEqual(object, other);
// => true
// using a customizer callback
var array = ['hello', 'goodbye'];
var other = ['hi', 'goodbye'];
_.isEqual(array, other, function(value, other) {
if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
return true;
}
});
// => true
_.isError(value)
Checks if value
is an Error
, EvalError
, RangeError
, ReferenceError
,
SyntaxError
, TypeError
, or URIError
object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is an error object, else false
.
Example
_.isError(new Error);
// => true
_.isError(Error);
// => false
_.isFinite(value)
Checks if value
is a finite primitive number.
Note: This method is based on Number.isFinite
.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is a finite number, else false
.
Example
_.isFinite(10);
// => true
_.isFinite('10');
// => false
_.isFinite(true);
// => false
_.isFinite(Object(10));
// => false
_.isFinite(Infinity);
// => false
_.isFunction(value)
Checks if value
is classified as a Function
object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isFunction(_);
// => true
_.isFunction(/abc/);
// => 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
object
(Object): The object to inspect.source
(Object): The object of property values to match.[customizer]
(Function): The function to customize value comparisons.[thisArg]
(*): Thethis
binding ofcustomizer
.
Returns
(boolean): Returns true
if object
is a match, else false
.
Example
var object = { 'user': 'fred', 'age': 40 };
_.isMatch(object, { 'age': 40 });
// => true
_.isMatch(object, { 'age': 36 });
// => false
// using a customizer callback
var object = { 'greeting': 'hello' };
var source = { 'greeting': 'hi' };
_.isMatch(object, source, function(value, other) {
return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
});
// => 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
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is NaN
, else false
.
Example
_.isNaN(NaN);
// => true
_.isNaN(new Number(NaN));
// => true
isNaN(undefined);
// => true
_.isNaN(undefined);
// => false
_.isNative(value)
Checks if value
is a native function.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is a native function, else false
.
Example
_.isNative(Array.prototype.push);
// => true
_.isNative(_);
// => false
_.isNull(value)
Checks if value
is null
.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is null
, else false
.
Example
_.isNull(null);
// => true
_.isNull(void 0);
// => 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
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isNumber(8.4);
// => true
_.isNumber(NaN);
// => true
_.isNumber('8.4');
// => 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
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is an object, else false
.
Example
_.isObject({});
// => true
_.isObject([1, 2, 3]);
// => true
_.isObject(1);
// => 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
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is a plain object, else false
.
Example
function Foo() {
this.a = 1;
}
_.isPlainObject(new Foo);
// => false
_.isPlainObject([1, 2, 3]);
// => false
_.isPlainObject({ 'x': 0, 'y': 0 });
// => true
_.isPlainObject(Object.create(null));
// => true
_.isRegExp(value)
Checks if value
is classified as a RegExp
object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isRegExp(/abc/);
// => true
_.isRegExp('/abc/');
// => false
_.isString(value)
Checks if value
is classified as a String
primitive or object.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isString('abc');
// => true
_.isString(1);
// => false
_.isTypedArray(value)
Checks if value
is classified as a typed array.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is correctly classified, else false
.
Example
_.isTypedArray(new Uint8Array);
// => true
_.isTypedArray([]);
// => false
_.isUndefined(value)
Checks if value
is undefined
.
Arguments
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is undefined
, else false
.
Example
_.isUndefined(void 0);
// => true
_.isUndefined(null);
// => false
_.lt(value, other)
Checks if value
is less than other
.
Arguments
value
(*): The value to compare.other
(*): The other value to compare.
Returns
(boolean): Returns true
if value
is less than other
, else false
.
Example
_.lt(1, 3);
// => true
_.lt(3, 3);
// => false
_.lt(3, 1);
// => false
_.lte(value, other)
Checks if value
is less than or equal to other
.
Arguments
value
(*): The value to compare.other
(*): The other value to compare.
Returns
(boolean): Returns true
if value
is less than or equal to other
, else false
.
Example
_.lte(1, 3);
// => true
_.lte(3, 3);
// => true
_.lte(3, 1);
// => false
_.toArray(value)
Converts value
to an array.
Arguments
value
(*): The value to convert.
Returns
(Array): Returns the converted array.
Example
(function() {
return _.toArray(arguments).slice(1);
}(1, 2, 3));
// => [2, 3]
_.toPlainObject(value)
Converts value
to a plain object flattening inherited enumerable
properties of value
to own properties of the plain object.
Arguments
value
(*): The value to convert.
Returns
(Object): Returns the converted plain object.
Example
function Foo() {
this.b = 2;
}
Foo.prototype.c = 3;
_.assign({ 'a': 1 }, new Foo);
// => { 'a': 1, 'b': 2 }
_.assign({ 'a': 1 }, _.toPlainObject(new Foo));
// => { 'a': 1, 'b': 2, 'c': 3 }