_.assignIn(object, [sources])

source npm package

This method is like _.assign except that it iterates over own and inherited source properties.

Note: This method mutates object.

Since

4.0.0

Aliases

_.extend

Arguments

  1. object (Object): The destination object.
  2. [sources] (...Object): The source objects.

Returns

(Object): Returns object.

Example

function Foo() {
  this.a = 1;
}
 
function Bar() {
  this.c = 3;
}
 
Foo.prototype.b = 2;
Bar.prototype.d = 4;
 
_.assignIn({ 'a'0 }, new Foo, new Bar);
// => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }

_.before(n, func)

source npm package

Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times. Subsequent calls to the created function return the result of the last func invocation.

Since

3.0.0

Arguments

  1. n (number): The number of calls at which func is no longer invoked.
  2. func (Function): The function to restrict.

Returns

(Function): Returns the new restricted function.

Example

jQuery(element).on('click', _.before(5, addContactToList));
// => Allows adding up to 4 contacts to the list.

_.bind(func, thisArg, [partials])

source npm package

Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.

The _.bind.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.

Note: Unlike native Function#bind, this method doesn't set the "length" property of bound functions.

Since

0.1.0

Arguments

  1. func (Function): The function to bind.
  2. thisArg (*): The this binding of func.
  3. [partials] (...*): The arguments to be partially applied.

Returns

(Function): Returns the new bound function.

Example

function greet(greeting, punctuation) {
  return greeting + ' ' + this.user + punctuation;
}
 
var object = { 'user''fred' };
 
var bound = _.bind(greet, object, 'hi');
bound('!');
// => 'hi fred!'
 
// Bound with placeholders.
var bound = _.bind(greet, object, _, '!');
bound('hi');
// => 'hi fred!'

_.chain(value)

source

Creates a lodash wrapper instance that wraps value with explicit method chain sequences enabled. The result of such sequences must be unwrapped with _#value.

Since

1.3.0

Arguments

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

Returns

(Object): Returns the new lodash wrapper instance.

Example

var users = [
  { 'user''barney',  'age'36 },
  { 'user''fred',    'age'40 },
  { 'user''pebbles', 'age'1 }
];
 
var youngest = _
  .chain(users)
  .sortBy('age')
  .map(function(o) {
    return o.user + ' is ' + o.age;
  })
  .head()
  .value();
// => 'pebbles is 1'

_.clone(value)

source npm package

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

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

_.compact(array)

source npm package

Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.

Since

0.1.0

Arguments

  1. array (Array): The array to compact.

Returns

(Array): Returns the new array of filtered values.

Example

_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]

_.concat(array, [values])

source npm package

Creates a new array concatenating array with any additional arrays and/or values.

Since

4.0.0

Arguments

  1. array (Array): The array to concatenate.
  2. [values] (...*): The values to concatenate.

Returns

(Array): Returns the new concatenated array.

Example

var array = [1];
var other = _.concat(array, 2, [3], [[4]]);
 
console.log(other);
// => [1, 2, 3, [4]]
 
console.log(array);
// => [1]

_.create(prototype, [properties])

source npm package

Creates an object that inherits from the prototype object. If a properties object is given, its own enumerable string keyed properties are assigned to the created object.

Since

2.3.0

Arguments

  1. prototype (Object): The object to inherit from.
  2. [properties] (Object): The properties to assign to the object.

Returns

(Object): Returns the new object.

Example

function Shape() {
  this.x = 0;
  this.y = 0;
}
 
function Circle() {
  Shape.call(this);
}
 
Circle.prototype = _.create(Shape.prototype, {
  'constructor': Circle
});
 
var circle = new Circle;
circle instanceof Circle;
// => true
 
circle instanceof Shape;
// => true

_.defaults(object, [sources])

source npm package

Assigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to undefined. Source objects are applied from left to right. Once a property is set, additional values of the same property are ignored.

Note: This method mutates object.

Since

0.1.0

Arguments

  1. object (Object): The destination object.
  2. [sources] (...Object): The source objects.

Returns

(Object): Returns object.

Example

_.defaults({ 'a'1 }, { 'b'2 }, { 'a'3 });
// => { 'a': 1, 'b': 2 }

_.defer(func, [args])

source npm package

Defers invoking the func until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.

Since

0.1.0

Arguments

  1. func (Function): The function to defer.
  2. [args] (...*): The arguments to invoke func with.

Returns

(number): Returns the timer id.

Example

_.defer(function(text) {
  console.log(text);
}, 'deferred');
// => Logs 'deferred' after one millisecond.

_.delay(func, wait, [args])

source npm package

Invokes func after wait milliseconds. Any additional arguments are provided to func when it's invoked.

Since

0.1.0

Arguments

  1. func (Function): The function to delay.
  2. wait (number): The number of milliseconds to delay invocation.
  3. [args] (...*): The arguments to invoke func with.

Returns

(number): Returns the timer id.

Example

_.delay(function(text) {
  console.log(text);
}, 1000, 'later');
// => Logs 'later' after one second.

_.escape([string=''])

source npm package

Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.

Note: No other characters are escaped. To escape additional characters use a third-party library like he.

Though the ">" character is escaped for symmetry, characters like ">" and "/" don't need escaping in HTML and have no special meaning unless they're part of a tag or unquoted attribute value. See Mathias Bynens's article (under "semi-related fun fact") for more details.

When working with HTML you should always quote attribute values to reduce XSS vectors.

Since

0.1.0

Arguments

  1. [string=''] (string): The string to escape.

Returns

(string): Returns the escaped string.

Example

_.escape('fred, barney, & pebbles');
// => 'fred, barney, &ampamp; pebbles'

_.every(collection, [predicate=_.identity])

source npm package

Checks if predicate returns truthy for all elements of collection. Iteration is stopped once predicate returns falsey. The predicate is invoked with three arguments: (value, index|key, collection).

Note: This method returns true for empty collections because everything is true of elements of empty collections.

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [predicate=_.identity] (Function): The function invoked per iteration.

Returns

(boolean): Returns true if all elements pass the predicate check, else false.

Example

_.every([true, 1, null, 'yes'], Boolean);
// => false
 
var users = [
  { 'user''barney', 'age'36, 'active': false },
  { 'user''fred',   'age'40, 'active': false }
];
 
// The `_.matches` iteratee shorthand.
_.every(users, { 'user''barney', 'active': false });
// => false
 
// The `_.matchesProperty` iteratee shorthand.
_.every(users, ['active', false]);
// => true
 
// The `_.property` iteratee shorthand.
_.every(users, 'active');
// => false

_.filter(collection, [predicate=_.identity])

source npm package

Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).

Note: Unlike _.remove, this method returns a new array.

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [predicate=_.identity] (Function): The function invoked per iteration.

Returns

(Array): Returns the new filtered array.

Example

var users = [
  { 'user''barney', 'age'36, 'active': true },
  { 'user''fred',   'age'40, 'active': false }
];
 
_.filter(users, function(o) { return !o.active; });
// => objects for ['fred']
 
// The `_.matches` iteratee shorthand.
_.filter(users, { 'age'36, 'active': true });
// => objects for ['barney']
 
// The `_.matchesProperty` iteratee shorthand.
_.filter(users, ['active', false]);
// => objects for ['fred']
 
// The `_.property` iteratee shorthand.
_.filter(users, 'active');
// => objects for ['barney']

_.find(collection, [predicate=_.identity], [fromIndex=0])

source npm package

Iterates over elements of collection, returning the first element predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to inspect.
  2. [predicate=_.identity] (Function): The function invoked per iteration.
  3. [fromIndex=0] (number): The index to search from.

Returns

(*): Returns the matched element, else undefined.

Example

var users = [
  { 'user''barney',  'age'36, 'active': true },
  { 'user''fred',    'age'40, 'active': false },
  { 'user''pebbles', 'age'1,  'active': true }
];
 
_.find(users, function(o) { return o.age < 40; });
// => object for 'barney'
 
// The `_.matches` iteratee shorthand.
_.find(users, { 'age'1, 'active': true });
// => object for 'pebbles'
 
// The `_.matchesProperty` iteratee shorthand.
_.find(users, ['active', false]);
// => object for 'fred'
 
// The `_.property` iteratee shorthand.
_.find(users, 'active');
// => object for 'barney'

_.flatten(array)

source npm package

Flattens array a single level deep.

Since

0.1.0

Arguments

  1. array (Array): The array to flatten.

Returns

(Array): Returns the new flattened array.

Example

_.flatten([1, [2, [3, [4]], 5]]);
// => [1, 2, [3, [4]], 5]

_.flattenDeep(array)

source npm package

Recursively flattens array.

Since

3.0.0

Arguments

  1. array (Array): The array to flatten.

Returns

(Array): Returns the new flattened array.

Example

_.flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]

_.forEach(collection, [iteratee=_.identity])

source npm package

Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.

Note: As with other "Collections" methods, objects with a "length" property are iterated like arrays. To avoid this behavior use _.forIn or _.forOwn for object iteration.

Since

0.1.0

Aliases

_.each

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [iteratee=_.identity] (Function): The function invoked per iteration.

Returns

(*): Returns collection.

Example

_.forEach([1, 2], function(value) {
  console.log(value);
});
// => Logs `1` then `2`.
 
_.forEach({ 'a'1, 'b'2 }, function(value, key) {
  console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).

_.has(object, path)

source npm package

Checks if path is a direct property of object.

Since

0.1.0

Arguments

  1. object (Object): The object to query.
  2. path (Array|string): The path to check.

Returns

(boolean): Returns true if path exists, else false.

Example

var object = { 'a': { 'b'2 } };
var other = _.create({ 'a': _.create({ 'b'2 }) });
 
_.has(object, 'a');
// => true
 
_.has(object, 'a.b');
// => true
 
_.has(object, ['a', 'b']);
// => true
 
_.has(other, 'a');
// => false

source npm package

Gets the first element of array.

Since

0.1.0

Aliases

_.first

Arguments

  1. array (Array): The array to query.

Returns

(*): Returns the first element of array.

Example

_.head([1, 2, 3]);
// => 1
 
_.head([]);
// => undefined

_.identity(value)

source npm package

This method returns the first argument it receives.

Since

0.1.0

Arguments

  1. value (*): Any value.

Returns

(*): Returns value.

Example

var object = { 'a'1 };
 
console.log(_.identity(object) === object);
// => true

_.indexOf(array, value, [fromIndex=0])

source npm package

Gets the index at which the first occurrence of value is found in array using SameValueZero for equality comparisons. If fromIndex is negative, it's used as the offset from the end of array.

Since

0.1.0

Arguments

  1. array (Array): The array to inspect.
  2. value (*): The value to search for.
  3. [fromIndex=0] (number): The index to search from.

Returns

(number): Returns the index of the matched value, else -1.

Example

_.indexOf([1, 2, 1, 2], 2);
// => 1
 
// Search from the `fromIndex`.
_.indexOf([1, 2, 1, 2], 2, 2);
// => 3

_.isArguments(value)

source npm package

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

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

_.isArray(value)

source npm package

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

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

_.isBoolean(value)

source npm package

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

_.isBoolean(false);
// => true
 
_.isBoolean(null);
// => false

_.isDate(value)

source npm package

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

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

_.isEmpty(value)

source npm package

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

_.isEmpty(null);
// => true
 
_.isEmpty(true);
// => true
 
_.isEmpty(1);
// => true
 
_.isEmpty([1, 2, 3]);
// => false
 
_.isEmpty({ 'a'1 });
// => false

_.isEqual(value, other)

source npm package

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

var object = { 'a'1 };
var other = { 'a'1 };
 
_.isEqual(object, other);
// => true
 
object === other;
// => false

_.isFinite(value)

source npm package

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

_.isFinite(3);
// => true
 
_.isFinite(Number.MIN_VALUE);
// => true
 
_.isFinite(Infinity);
// => false
 
_.isFinite('3');
// => false

_.isFunction(value)

source npm package

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

_.isFunction(_);
// => true
 
_.isFunction(/abc/);
// => false

_.isNaN(value)

source npm package

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

_.isNaN(NaN);
// => true
 
_.isNaN(new Number(NaN));
// => true
 
isNaN(undefined);
// => true
 
_.isNaN(undefined);
// => false

_.isNull(value)

source npm package

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

_.isNull(null);
// => true
 
_.isNull(void 0);
// => false

_.isNumber(value)

source npm package

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

_.isNumber(3);
// => true
 
_.isNumber(Number.MIN_VALUE);
// => true
 
_.isNumber(Infinity);
// => true
 
_.isNumber('3');
// => false

_.isObject(value)

source npm package

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

_.isObject({});
// => true
 
_.isObject([1, 2, 3]);
// => true
 
_.isObject(_.noop);
// => true
 
_.isObject(null);
// => false

_.isRegExp(value)

source npm package

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

_.isRegExp(/abc/);
// => true
 
_.isRegExp('/abc/');
// => false

_.isString(value)

source npm package

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

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

_.isUndefined(value)

source npm package

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

_.isUndefined(void 0);
// => true
 
_.isUndefined(null);
// => false

_.iteratee([func=_.identity])

source npm package

Creates a function that invokes func with the arguments of the created function. If func is a property name, the created function returns the property value for a given element. If func is an array or object, the created function returns true for elements that contain the equivalent source properties, otherwise it returns false.

Since

4.0.0

Arguments

  1. [func=_.identity] (*): The value to convert to a callback.

Returns

(Function): Returns the callback.

Example

var users = [
  { 'user''barney', 'age'36, 'active': true },
  { 'user''fred',   'age'40, 'active': false }
];
 
// The `_.matches` iteratee shorthand.
_.filter(users, _.iteratee({ 'user''barney', 'active': true }));
// => [{ 'user': 'barney', 'age': 36, 'active': true }]
 
// The `_.matchesProperty` iteratee shorthand.
_.filter(users, _.iteratee(['user', 'fred']));
// => [{ 'user': 'fred', 'age': 40 }]
 
// The `_.property` iteratee shorthand.
_.map(users, _.iteratee('user'));
// => ['barney', 'fred']
 
// Create custom iteratee shorthands.
_.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  return !_.isRegExp(func) ? iteratee(func) : function(string) {
    return func.test(string);
  };
});
 
_.filter(['abc', 'def'], /ef/);
// => ['def']

_.keys(object)

source npm package

Creates an array of the own enumerable property names of object.

Note: Non-object values are coerced to objects. See the ES spec for more details.

Since

0.1.0

Arguments

  1. object (Object): The object to query.

Returns

(Array): Returns the array of property names.

Example

function Foo() {
  this.a = 1;
  this.b = 2;
}
 
Foo.prototype.c = 3;
 
_.keys(new Foo);
// => ['a', 'b'] (iteration order is not guaranteed)
 
_.keys('hi');
// => ['0', '1']

_.last(array)

source npm package

Gets the last element of array.

Since

0.1.0

Arguments

  1. array (Array): The array to query.

Returns

(*): Returns the last element of array.

Example

_.last([1, 2, 3]);
// => 3

_.map(collection, [iteratee=_.identity])

source npm package

Creates an array of values by running each element in collection thru iteratee. The iteratee is invoked with three arguments:
(value, index|key, collection).

Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues, _.reject, and _.some.

The guarded methods are:
ary, chunk, curry, curryRight, drop, dropRight, every, fill, invert, parseInt, random, range, rangeRight, repeat, sampleSize, slice, some, sortBy, split, take, takeRight, template, trim, trimEnd, trimStart, and words

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [iteratee=_.identity] (Function): The function invoked per iteration.

Returns

(Array): Returns the new mapped array.

Example

function square(n) {
  return n * n;
}
 
_.map([4, 8], square);
// => [16, 64]
 
_.map({ 'a'4, 'b'8 }, square);
// => [16, 64] (iteration order is not guaranteed)
 
var users = [
  { 'user''barney' },
  { 'user''fred' }
];
 
// The `_.property` iteratee shorthand.
_.map(users, 'user');
// => ['barney', 'fred']

_.matches(source)

source npm package

Creates a function that performs a partial deep comparison between a given object and source, returning true if the given object has equivalent property values, else false.

Note: The created function is equivalent to _.isMatch with source 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. source (Object): The object of property values to match.

Returns

(Function): Returns the new spec function.

Example

var objects = [
  { 'a'1, 'b'2, 'c'3 },
  { 'a'4, 'b'5, 'c'6 }
];
 
_.filter(objects, _.matches({ 'a'4, 'c'6 }));
// => [{ 'a': 4, 'b': 5, 'c': 6 }]

_.max(array)

source npm package

Computes the maximum value of array. If array is empty or falsey, undefined is returned.

Since

0.1.0

Arguments

  1. array (Array): The array to iterate over.

Returns

(*): Returns the maximum value.

Example

_.max([4, 2, 8, 6]);
// => 8
 
_.max([]);
// => undefined

_.min(array)

source npm package

Computes the minimum value of array. If array is empty or falsey, undefined is returned.

Since

0.1.0

Arguments

  1. array (Array): The array to iterate over.

Returns

(*): Returns the minimum value.

Example

_.min([4, 2, 8, 6]);
// => 2
 
_.min([]);
// => undefined

_.mixin([object=lodash], source, [options={}])

source npm package

Adds all own enumerable string keyed function properties of a source object to the destination object. If object is a function, then methods are added to its prototype as well.

Note: Use _.runInContext to create a pristine lodash function to avoid conflicts caused by modifying the original.

Since

0.1.0

Arguments

  1. [object=lodash] (Function|Object): The destination object.
  2. source (Object): The object of functions to add.
  3. [options={}] (Object): The options object.
  4. [options.chain=true] (boolean): Specify whether mixins are chainable.

Returns

(*): Returns object.

Example

function vowels(string) {
  return _.filter(string, function(v) {
    return /[aeiou]/i.test(v);
  });
}
 
_.mixin({ 'vowels': vowels });
_.vowels('fred');
// => ['e']
 
_('fred').vowels().value();
// => ['e']
 
_.mixin({ 'vowels': vowels }, { 'chain': false });
_('fred').vowels();
// => ['e']

_.negate(predicate)

source npm package

Creates a function that negates the result of the predicate func. The func predicate is invoked with the this binding and arguments of the created function.

Since

3.0.0

Arguments

  1. predicate (Function): The predicate to negate.

Returns

(Function): Returns the new negated function.

Example

function isEven(n) {
  return n % 2 == 0;
}
 
_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
// => [1, 3, 5]

_.noConflict()

source npm package

Reverts the _ variable to its previous value and returns a reference to the lodash function.

Since

0.1.0

Returns

(Function): Returns the lodash function.

Example

var lodash = _.noConflict();

_.noop()

source npm package

This method returns undefined.

Since

2.3.0

Example

_.times(2, _.noop);
// => [undefined, undefined]

_.once(func)

source npm package

Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation. The func is invoked with the this binding and arguments of the created function.

Since

0.1.0

Arguments

  1. func (Function): The function to restrict.

Returns

(Function): Returns the new restricted function.

Example

var initialize = _.once(createApplication);
initialize();
initialize();
// => `createApplication` is invoked once

_.pick(object, [paths])

source npm package

Creates an object composed of the picked object properties.

Since

0.1.0

Arguments

  1. object (Object): The source object.
  2. [paths] (...(string|string[])): The property paths to pick.

Returns

(Object): Returns the new object.

Example

var object = { 'a'1, 'b''2', 'c'3 };
 
_.pick(object, ['a', 'c']);
// => { 'a': 1, 'c': 3 }

_.reduce(collection, [iteratee=_.identity], [accumulator])

source npm package

Reduces collection to a value which is the accumulated result of running each element in collection thru iteratee, where each successive invocation is supplied the return value of the previous. If accumulator is not given, the first element of collection is used as the initial value. The iteratee is invoked with four arguments:
(accumulator, value, index|key, collection).

Many lodash methods are guarded to work as iteratees for methods like _.reduce, _.reduceRight, and _.transform.

The guarded methods are:
assign, defaults, defaultsDeep, includes, merge, orderBy, and sortBy

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [iteratee=_.identity] (Function): The function invoked per iteration.
  3. [accumulator] (*): The initial value.

Returns

(*): Returns the accumulated value.

Example

_.reduce([1, 2], function(sum, n) {
  return sum + n;
}, 0);
// => 3
 
_.reduce({ 'a'1, 'b'2, 'c'1 }, function(result, value, key) {
  (result[value] || (result[value] = [])).push(key);
  return result;
}, {});
// => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)

_.result(object, path, [defaultValue])

source npm package

This method is like _.get except that if the resolved value is a function it's invoked with the this binding of its parent object and its result is returned.

Since

0.1.0

Arguments

  1. object (Object): The object to query.
  2. path (Array|string): The path of the property to resolve.
  3. [defaultValue] (*): The value returned for undefined resolved values.

Returns

(*): Returns the resolved value.

Example

var object = { 'a': [{ 'b': { 'c1'3, 'c2': _.constant(4) } }] };
 
_.result(object, 'a[0].b.c1');
// => 3
 
_.result(object, 'a[0].b.c2');
// => 4
 
_.result(object, 'a[0].b.c3', 'default');
// => 'default'
 
_.result(object, 'a[0].b.c3', _.constant('default'));
// => 'default'

_.size(collection)

source npm package

Gets the size of collection by returning its length for array-like values or the number of own enumerable string keyed properties for objects.

Since

0.1.0

Arguments

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

Returns

(number): Returns the collection size.

Example

_.size([1, 2, 3]);
// => 3
 
_.size({ 'a'1, 'b'2 });
// => 2
 
_.size('pebbles');
// => 7

_.slice(array, [start=0], [end=array.length])

source npm package

Creates a slice of array from start up to, but not including, end.

Note: This method is used instead of Array#slice to ensure dense arrays are returned.

Since

3.0.0

Arguments

  1. array (Array): The array to slice.
  2. [start=0] (number): The start position.
  3. [end=array.length] (number): The end position.

Returns

(Array): Returns the slice of array.

_.some(collection, [predicate=_.identity])

source npm package

Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. The predicate is invoked with three arguments: (value, index|key, collection).

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [predicate=_.identity] (Function): The function invoked per iteration.

Returns

(boolean): Returns true if any element passes the predicate check, else false.

Example

_.some([null, 0, 'yes', false], Boolean);
// => true
 
var users = [
  { 'user''barney', 'active': true },
  { 'user''fred',   'active': false }
];
 
// The `_.matches` iteratee shorthand.
_.some(users, { 'user''barney', 'active': false });
// => false
 
// The `_.matchesProperty` iteratee shorthand.
_.some(users, ['active', false]);
// => true
 
// The `_.property` iteratee shorthand.
_.some(users, 'active');
// => true

_.sortBy(collection, [iteratees=[_.identity]])

source npm package

Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratees are invoked with one argument: (value).

Since

0.1.0

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. [iteratees=[_.identity]] (...(Function|Function[])): The iteratees to sort by.

Returns

(Array): Returns the new sorted array.

Example

var users = [
  { 'user''fred',   'age'48 },
  { 'user''barney', 'age'36 },
  { 'user''fred',   'age'40 },
  { 'user''barney', 'age'34 }
];
 
_.sortBy(users, [function(o) { return o.user; }]);
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
 
_.sortBy(users, ['user', 'age']);
// => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]

_.tap(value, interceptor)

source

This method invokes interceptor and returns value. The interceptor is invoked with one argument; (value). The purpose of this method is to "tap into" a method chain sequence in order to modify intermediate results.

Since

0.1.0

Arguments

  1. value (*): The value to provide to interceptor.
  2. interceptor (Function): The function to invoke.

Returns

(*): Returns value.

Example

_([1, 2, 3])
 .tap(function(array) {
// Mutate input array.
   array.pop();
 })
 .reverse()
 .value();
// => [2, 1]

_.thru(value, interceptor)

source

This method is like _.tap except that it returns the result of interceptor. The purpose of this method is to "pass thru" values replacing intermediate results in a method chain sequence.

Since

3.0.0

Arguments

  1. value (*): The value to provide to interceptor.
  2. interceptor (Function): The function to invoke.

Returns

(*): Returns the result of interceptor.

Example

_('  abc  ')
 .chain()
 .trim()
 .thru(function(value) {
   return [value];
 })
 .value();
// => ['abc']

_.toArray(value)

source npm package

Converts value to an array.

Since

0.1.0

Arguments

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

Returns

(Array): Returns the converted array.

Example

_.toArray({ 'a'1, 'b'2 });
// => [1, 2]
 
_.toArray('abc');
// => ['a', 'b', 'c']
 
_.toArray(1);
// => []
 
_.toArray(null);
// => []

_.uniqueId([prefix=''])

source npm package

Generates a unique ID. If prefix is given, the ID is appended to it.

Since

0.1.0

Arguments

  1. [prefix=''] (string): The value to prefix the ID with.

Returns

(string): Returns the unique ID.

Example

_.uniqueId('contact_');
// => 'contact_104'
 
_.uniqueId();
// => '105'

_.values(object)

source npm package

Creates an array of the own enumerable string keyed property values of object.

Note: Non-object values are coerced to objects.

Since

0.1.0

Arguments

  1. object (Object): The object to query.

Returns

(Array): Returns the array of property values.

Example

function Foo() {
  this.a = 1;
  this.b = 2;
}
 
Foo.prototype.c = 3;
 
_.values(new Foo);
// => [1, 2] (iteration order is not guaranteed)
 
_.values('hi');
// => ['h', 'i']
Report a Bug