_.castArray(value)

Casts value as an array if it’s not one.

Since

4.4.0

Arguments

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

Returns

(Array): Returns the cast array.

Example

  1. _.castArray(1);
  2. // => [1]
  3. _.castArray({ 'a': 1 });
  4. // => [{ 'a': 1 }]
  5. _.castArray('abc');
  6. // => ['abc']
  7. _.castArray(null);
  8. // => [null]
  9. _.castArray(undefined);
  10. // => [undefined]
  11. _.castArray();
  12. // => []
  13. var array = [1, 2, 3];
  14. console.log(_.castArray(array) === array);
  15. // => true

_.clone(value)

Creates a shallow clone of value.

Note: This method is loosely based on the structured clone algorithm and supports cloning arrays, array buffers, booleans, date objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. The own enumerable properties of arguments objects are cloned as plain objects. An empty object is returned for uncloneable values such as error objects, functions, DOM nodes, and WeakMaps.

Since

0.1.0

Arguments

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

Returns

(*): Returns the cloned value.

Example

  1. var objects = [{ 'a': 1 }, { 'b': 2 }];
  2. var shallow = _.clone(objects);
  3. console.log(shallow[0] === objects[0]);
  4. // => true

_.cloneDeep(value)

This method is like _.clone except that it recursively clones value.

Since

1.0.0

Arguments

  1. value (*): The value to recursively clone.

Returns

(*): Returns the deep cloned value.

Example

  1. var objects = [{ 'a': 1 }, { 'b': 2 }];
  2. var deep = _.cloneDeep(objects);
  3. console.log(deep[0] === objects[0]);
  4. // => false

_.cloneDeepWith(value, [customizer])

This method is like _.cloneWith except that it recursively clones value.

Since

4.0.0

Arguments

  1. value (*): The value to recursively clone.
  2. [customizer] (Function): The function to customize cloning.

Returns

(*): Returns the deep cloned value.

Example

  1. function customizer(value) {
  2. if (_.isElement(value)) {
  3. return value.cloneNode(true);
  4. }
  5. }
  6. var el = _.cloneDeepWith(document.body, customizer);
  7. console.log(el === document.body);
  8. // => false
  9. console.log(el.nodeName);
  10. // => 'BODY'
  11. console.log(el.childNodes.length);
  12. // => 20

_.cloneWith(value, [customizer])

This method is like _.clone except that it accepts customizer which is invoked to produce the cloned value. If customizer returns undefined, cloning is handled by the method instead. The customizer is invoked with up to four arguments; (value [, index|key, object, stack]).

Since

4.0.0

Arguments

  1. value (*): The value to clone.
  2. [customizer] (Function): The function to customize cloning.

Returns

(*): Returns the cloned value.

Example

  1. function customizer(value) {
  2. if (_.isElement(value)) {
  3. return value.cloneNode(false);
  4. }
  5. }
  6. var el = _.cloneWith(document.body, customizer);
  7. console.log(el === document.body);
  8. // => false
  9. console.log(el.nodeName);
  10. // => 'BODY'
  11. console.log(el.childNodes.length);
  12. // => 0

_.conformsTo(object, source)

Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.

Note: This method is equivalent to _.conforms when source is partially applied.

Since

4.14.0

Arguments

  1. object (Object): The object to inspect.
  2. source (Object): The object of property predicates to conform to.

Returns

(boolean): Returns true if object conforms, else false.

Example

  1. var object = { 'a': 1, 'b': 2 };
  2. _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  3. // => true
  4. _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  5. // => false

_.eq(value, other)

Performs a SameValueZero comparison between two values to determine if they are equivalent.

Since

4.0.0

Arguments

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

Returns

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

Example

  1. var object = { 'a': 1 };
  2. var other = { 'a': 1 };
  3. _.eq(object, object);
  4. // => true
  5. _.eq(object, other);
  6. // => false
  7. _.eq('a', 'a');
  8. // => true
  9. _.eq('a', Object('a'));
  10. // => false
  11. _.eq(NaN, NaN);
  12. // => true

_.gt(value, other)

Checks if value is greater than other.

Since

3.9.0

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.

Since

3.9.0

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 likely an arguments object.

Since

0.1.0

Arguments

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

Returns

(boolean): Returns true if value is an arguments object, 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.

Since

0.1.0

Arguments

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

Returns

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

Example

  1. _.isArray([1, 2, 3]);
  2. // => true
  3. _.isArray(document.body.children);
  4. // => false
  5. _.isArray('abc');
  6. // => false
  7. _.isArray(_.noop);
  8. // => false

_.isArrayBuffer(value)

Checks if value is classified as an ArrayBuffer object.

Since

4.3.0

Arguments

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

Returns

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

Example

  1. _.isArrayBuffer(new ArrayBuffer(2));
  2. // => true
  3. _.isArrayBuffer(new Array(2));
  4. // => false

_.isArrayLike(value)

Checks if value is array-like. A value is considered array-like if it’s not a function and has a value.length that’s an integer greater than or equal to 0 and less than or equal to Number.MAX_SAFE_INTEGER.

Since

4.0.0

Arguments

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

Returns

(boolean): Returns true if value is array-like, else false.

Example

  1. _.isArrayLike([1, 2, 3]);
  2. // => true
  3. _.isArrayLike(document.body.children);
  4. // => true
  5. _.isArrayLike('abc');
  6. // => true
  7. _.isArrayLike(_.noop);
  8. // => false

_.isArrayLikeObject(value)

This method is like _.isArrayLike except that it also checks if value is an object.

Since

4.0.0

Arguments

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

Returns

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

Example

  1. _.isArrayLikeObject([1, 2, 3]);
  2. // => true
  3. _.isArrayLikeObject(document.body.children);
  4. // => true
  5. _.isArrayLikeObject('abc');
  6. // => false
  7. _.isArrayLikeObject(_.noop);
  8. // => false

_.isBoolean(value)

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

Since

0.1.0

Arguments

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

Returns

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

Example

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

_.isBuffer(value)

Checks if value is a buffer.

Since

4.3.0

Arguments

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

Returns

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

Example

  1. _.isBuffer(new Buffer(2));
  2. // => true
  3. _.isBuffer(new Uint8Array(2));
  4. // => false

_.isDate(value)

Checks if value is classified as a Date object.

Since

0.1.0

Arguments

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

Returns

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

Example

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

_.isElement(value)

Checks if value is likely a DOM element.

Since

0.1.0

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 an empty object, collection, map, or set.

Objects are considered empty if they have no own enumerable string keyed properties.

Array-like values such as arguments objects, arrays, buffers, strings, or jQuery-like collections are considered empty if they have a length of 0. Similarly, maps and sets are considered empty if they have a size of 0.

Since

0.1.0

Arguments

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

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)

Performs a deep comparison between two values to determine if they are equivalent.

Note: This method supports comparing arrays, array buffers, booleans, date objects, error objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. Object objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are compared by strict equality, i.e. ===.

Since

0.1.0

Arguments

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

Returns

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

Example

  1. var object = { 'a': 1 };
  2. var other = { 'a': 1 };
  3. _.isEqual(object, other);
  4. // => true
  5. object === other;
  6. // => false

_.isEqualWith(value, other, [customizer])

This method is like _.isEqual except that it accepts customizer which is invoked to compare values. If customizer returns undefined, comparisons are handled by the method instead. The customizer is invoked with up to six arguments: (objValue, othValue [, index|key, object, other, stack]).

Since

4.0.0

Arguments

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

Returns

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

Example

  1. function isGreeting(value) {
  2. return /^h(?:i|ello)$/.test(value);
  3. }
  4. function customizer(objValue, othValue) {
  5. if (isGreeting(objValue) && isGreeting(othValue)) {
  6. return true;
  7. }
  8. }
  9. var array = ['hello', 'goodbye'];
  10. var other = ['hi', 'goodbye'];
  11. _.isEqualWith(array, other, customizer);
  12. // => true

_.isError(value)

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

Since

3.0.0

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.

Since

0.1.0

Arguments

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

Returns

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

Example

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

_.isFunction(value)

Checks if value is classified as a Function object.

Since

0.1.0

Arguments

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

Returns

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

Example

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

_.isInteger(value)

Checks if value is an integer.

Note: This method is based on Number.isInteger.

Since

4.0.0

Arguments

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

Returns

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

Example

  1. _.isInteger(3);
  2. // => true
  3. _.isInteger(Number.MIN_VALUE);
  4. // => false
  5. _.isInteger(Infinity);
  6. // => false
  7. _.isInteger('3');
  8. // => false

_.isLength(value)

Checks if value is a valid array-like length.

Note: This method is loosely based on ToLength.

Since

4.0.0

Arguments

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

Returns

(boolean): Returns true if value is a valid length, else false.

Example

  1. _.isLength(3);
  2. // => true
  3. _.isLength(Number.MIN_VALUE);
  4. // => false
  5. _.isLength(Infinity);
  6. // => false
  7. _.isLength('3');
  8. // => false

_.isMap(value)

Checks if value is classified as a Map object.

Since

4.3.0

Arguments

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

Returns

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

Example

  1. _.isMap(new Map);
  2. // => true
  3. _.isMap(new WeakMap);
  4. // => false

_.isMatch(object, source)

Performs a partial deep comparison between object and source to determine if object contains equivalent property values.

Note: This method is equivalent to _.matches when source is partially applied.

Partial comparisons will match empty array and empty object source values against any array or object value, respectively. See _.isEqual for a list of supported value comparisons.

Since

3.0.0

Arguments

  1. object (Object): The object to inspect.
  2. source (Object): The object of property values to match.

Returns

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

Example

  1. var object = { 'a': 1, 'b': 2 };
  2. _.isMatch(object, { 'b': 2 });
  3. // => true
  4. _.isMatch(object, { 'b': 1 });
  5. // => false

_.isMatchWith(object, source, [customizer])

This method is like _.isMatch except that it accepts customizer which is invoked to compare values. If customizer returns undefined, comparisons are handled by the method instead. The customizer is invoked with five arguments: (objValue, srcValue, index|key, object, source).

Since

4.0.0

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 comparisons.

Returns

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

Example

  1. function isGreeting(value) {
  2. return /^h(?:i|ello)$/.test(value);
  3. }
  4. function customizer(objValue, srcValue) {
  5. if (isGreeting(objValue) && isGreeting(srcValue)) {
  6. return true;
  7. }
  8. }
  9. var object = { 'greeting': 'hello' };
  10. var source = { 'greeting': 'hi' };
  11. _.isMatchWith(object, source, customizer);
  12. // => true

_.isNaN(value)

Checks if value is NaN.

Note: This method is based on Number.isNaN and is not the same as global isNaN which returns true for undefined and other non-number values.

Since

0.1.0

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 pristine native function.

Note: This method can’t reliably detect native functions in the presence of the core-js package because core-js circumvents this kind of detection. Despite multiple requests, the core-js maintainer has made it clear: any attempt to fix the detection will be obstructed. As a result, we’re left with little choice but to throw an error. Unfortunately, this also affects packages, like babel-polyfill, which rely on core-js.

Since

3.0.0

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

_.isNil(value)

Checks if value is null or undefined.

Since

4.0.0

Arguments

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

Returns

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

Example

  1. _.isNil(null);
  2. // => true
  3. _.isNil(void 0);
  4. // => true
  5. _.isNil(NaN);
  6. // => false

_.isNull(value)

Checks if value is null.

Since

0.1.0

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.

Since

0.1.0

Arguments

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

Returns

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

Example

  1. _.isNumber(3);
  2. // => true
  3. _.isNumber(Number.MIN_VALUE);
  4. // => true
  5. _.isNumber(Infinity);
  6. // => true
  7. _.isNumber('3');
  8. // => false

_.isObject(value)

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

Since

0.1.0

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(_.noop);
  6. // => true
  7. _.isObject(null);
  8. // => false

_.isObjectLike(value)

Checks if value is object-like. A value is object-like if it’s not null and has a typeof result of “object”.

Since

4.0.0

Arguments

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

Returns

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

Example

  1. _.isObjectLike({});
  2. // => true
  3. _.isObjectLike([1, 2, 3]);
  4. // => true
  5. _.isObjectLike(_.noop);
  6. // => false
  7. _.isObjectLike(null);
  8. // => 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.

Since

0.8.0

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.

Since

0.1.0

Arguments

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

Returns

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

Example

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

_.isSafeInteger(value)

Checks if value is a safe integer. An integer is safe if it’s an IEEE-754 double precision number which isn’t the result of a rounded unsafe integer.

Note: This method is based on Number.isSafeInteger.

Since

4.0.0

Arguments

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

Returns

(boolean): Returns true if value is a safe integer, else false.

Example

  1. _.isSafeInteger(3);
  2. // => true
  3. _.isSafeInteger(Number.MIN_VALUE);
  4. // => false
  5. _.isSafeInteger(Infinity);
  6. // => false
  7. _.isSafeInteger('3');
  8. // => false

_.isSet(value)

Checks if value is classified as a Set object.

Since

4.3.0

Arguments

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

Returns

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

Example

  1. _.isSet(new Set);
  2. // => true
  3. _.isSet(new WeakSet);
  4. // => false

_.isString(value)

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

Since

0.1.0

Arguments

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

Returns

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

Example

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

_.isSymbol(value)

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

Since

4.0.0

Arguments

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

Returns

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

Example

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

_.isTypedArray(value)

Checks if value is classified as a typed array.

Since

3.0.0

Arguments

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

Returns

(boolean): Returns true if value is a typed array, else false.

Example

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

_.isUndefined(value)

Checks if value is undefined.

Since

0.1.0

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

_.isWeakMap(value)

Checks if value is classified as a WeakMap object.

Since

4.3.0

Arguments

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

Returns

(boolean): Returns true if value is a weak map, else false.

Example

  1. _.isWeakMap(new WeakMap);
  2. // => true
  3. _.isWeakMap(new Map);
  4. // => false

_.isWeakSet(value)

Checks if value is classified as a WeakSet object.

Since

4.3.0

Arguments

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

Returns

(boolean): Returns true if value is a weak set, else false.

Example

  1. _.isWeakSet(new WeakSet);
  2. // => true
  3. _.isWeakSet(new Set);
  4. // => false

_.lt(value, other)

Checks if value is less than other.

Since

3.9.0

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.

Since

3.9.0

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.

Since

0.1.0

Arguments

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

Returns

(Array): Returns the converted array.

Example

  1. _.toArray({ 'a': 1, 'b': 2 });
  2. // => [1, 2]
  3. _.toArray('abc');
  4. // => ['a', 'b', 'c']
  5. _.toArray(1);
  6. // => []
  7. _.toArray(null);
  8. // => []

_.toFinite(value)

Converts value to a finite number.

Since

4.12.0

Arguments

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

Returns

(number): Returns the converted number.

Example

  1. _.toFinite(3.2);
  2. // => 3.2
  3. _.toFinite(Number.MIN_VALUE);
  4. // => 5e-324
  5. _.toFinite(Infinity);
  6. // => 1.7976931348623157e+308
  7. _.toFinite('3.2');
  8. // => 3.2

_.toInteger(value)

Converts value to an integer.

Note: This method is loosely based on ToInteger.

Since

4.0.0

Arguments

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

Returns

(number): Returns the converted integer.

Example

  1. _.toInteger(3.2);
  2. // => 3
  3. _.toInteger(Number.MIN_VALUE);
  4. // => 0
  5. _.toInteger(Infinity);
  6. // => 1.7976931348623157e+308
  7. _.toInteger('3.2');
  8. // => 3

_.toLength(value)

Converts value to an integer suitable for use as the length of an array-like object.

Note: This method is based on ToLength.

Since

4.0.0

Arguments

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

Returns

(number): Returns the converted integer.

Example

  1. _.toLength(3.2);
  2. // => 3
  3. _.toLength(Number.MIN_VALUE);
  4. // => 0
  5. _.toLength(Infinity);
  6. // => 4294967295
  7. _.toLength('3.2');
  8. // => 3

_.toNumber(value)

Converts value to a number.

Since

4.0.0

Arguments

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

Returns

(number): Returns the number.

Example

  1. _.toNumber(3.2);
  2. // => 3.2
  3. _.toNumber(Number.MIN_VALUE);
  4. // => 5e-324
  5. _.toNumber(Infinity);
  6. // => Infinity
  7. _.toNumber('3.2');
  8. // => 3.2

_.toPlainObject(value)

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

Since

3.0.0

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 }

_.toSafeInteger(value)

Converts value to a safe integer. A safe integer can be compared and represented correctly.

Since

4.0.0

Arguments

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

Returns

(number): Returns the converted integer.

Example

  1. _.toSafeInteger(3.2);
  2. // => 3
  3. _.toSafeInteger(Number.MIN_VALUE);
  4. // => 0
  5. _.toSafeInteger(Infinity);
  6. // => 9007199254740991
  7. _.toSafeInteger('3.2');
  8. // => 3

_.toString(value)

Converts value to a string. An empty string is returned for null and undefined values. The sign of -0 is preserved.

Since

4.0.0

Arguments

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

Returns

(string): Returns the converted string.

Example

  1. _.toString(null);
  2. // => ''
  3. _.toString(-0);
  4. // => '-0'
  5. _.toString([1, 2, 3]);
  6. // => '1,2,3'