• Home
  • Search Tags
  • About

lodash

Topics related to lodash:

Getting started with lodash

Lodash is a library of utilities for manipulating and examining objects and arrays.

Chaining

Implicit chaining with _(arr1) and explicit chaining with _.chain(arr1) work in similar ways. The examples below show how they differ slighlty.

Explicit chaining with _.chain(...)

var arr1 = [10, 15, 20, 25, 30, 15, 25, 35];

var sumOfUniqueValues = _.chain(arr1)
    .uniq()
    .sum()       // sum returns a single value
    .value();    //   which must be unwrapped manually with explicit chaining

// sumOfUniqueValues is now 135

Implicit chaining with _(...)

var arr1 = [10, 15, 20, 25, 30, 15, 25, 35];

var sumOfUniqueValues = _(arr1)
    .uniq()
    .sum();      // sum returns a single value and is automatically unwrapped
                 //   with implicit chaining

// sumOfUniqueValues is now 135

The two behave differently when ending the chain with an operation that returns a single value: With implicit chaining, the "unwrapping" of the single value is implied. (Thus no need to call .value().)

(When the implicit chain ends with a collection value, you'll still need to unwrap the result with .value().)

Working with Lists and Arrays

Utils

Working with objects

Content on the page is taken from Stack Overflow Documentation

This site is NOT affiliated with Stack Overflow or any of the contributors. | Privacy Policy | Terms of Service