_(value)

Creates a lodash object, which wraps the given value, to enable method chaining.

In addition to Lo-Dash methods, wrappers also have the following Array methods:
concat, join, pop, push, reverse, shift, slice, sort, splice, and unshift

Chaining is supported in custom builds as long as the value method is implicitly or explicitly included in the build.

The chainable wrapper functions are:
after, assign, bind, bindAll, bindKey, chain, compact, compose, concat, countBy, createCallback, debounce, defaults, defer, delay, difference, filter, flatten, forEach, forIn, forOwn, functions, groupBy, initial, intersection, invert, invoke, keys, map, max, memoize, merge, min, object, omit, once, pairs, partial, partialRight, pick, pluck, push, range, reject, rest, reverse, shuffle, slice, sort, sortBy, splice, tap, throttle, times, toArray, transform, union, uniq, unshift, unzip, values, where, without, wrap, and zip

The non-chainable wrapper functions are:
clone, cloneDeep, contains, escape, every, find, has, identity, indexOf, isArguments, isArray, isBoolean, isDate, isElement, isEmpty, isEqual, isFinite, isFunction, isNaN, isNull, isNumber, isObject, isPlainObject, isRegExp, isString, isUndefined, join, lastIndexOf, mixin, noConflict, parseInt, pop, random, reduce, reduceRight, result, shift, size, some, sortedIndex, runInContext, template, unescape, uniqueId, and value

The wrapper functions first and last return wrapped values when n is passed, otherwise they return unwrapped values.

Aliases

chain

Arguments

  1. value (Mixed): The value to wrap in a lodash instance.

Returns

(Object): Returns a lodash instance.

Example

  1. var wrapped = _([1, 2, 3]);
  2. // returns an unwrapped value
  3. wrapped.reduce(function(sum, num) {
  4. return sum + num;
  5. });
  6. // => 6
  7. // returns a wrapped value
  8. var squares = wrapped.map(function(num) {
  9. return num * num;
  10. });
  11. _.isArray(squares);
  12. // => false
  13. _.isArray(squares.value());
  14. // => true

_.tap(value, interceptor)

Invokes interceptor with the value as the first argument, and then returns value. The purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.

Arguments

  1. value (Mixed): The value to pass to interceptor.
  2. interceptor (Function): The function to invoke.

Returns

(Mixed): Returns value.

Example

  1. _([1, 2, 3, 4])
  2. .filter(function(num) { return num % 2 == 0; })
  3. .tap(alert)
  4. .map(function(num) { return num * num; })
  5. .value();
  6. // => // [2, 4] (alerted)
  7. // => [4, 16]

_.prototype.toString()

Produces the toString result of the wrapped value.

Returns

(String): Returns the string result.

Example

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

_.prototype.valueOf()

Extracts the wrapped value.

Aliases

value

Returns

(Mixed): Returns the wrapped value.

Example

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