Skip to content

Instantly share code, notes, and snippets.

@vades
Last active May 21, 2019 10:20
Show Gist options
  • Save vades/23eb7a99f3ed2edc82e7a82b658c48ff to your computer and use it in GitHub Desktop.
Save vades/23eb7a99f3ed2edc82e7a82b658c48ff to your computer and use it in GitHub Desktop.
Using Lodash in Angular applications

Using Lodash in Angular applications

Lodash is a JavaScript library that helps programmers deal with all types of object.

Tested on

  • Angular: 7.0.3
  • Node: 8.10.0
  • Typescript: 3.1.6

Do npm install

$ npm install --save lodash
$ npm install --save-dev @types/lodash

Import the full lodash library

import * as _ from 'lodash' 

Usage

updateData(newItem: any){
    let index = _.findIndex(this.data, {id: newItem.id});
    ...
  }

OR import specific functions

import { findIndex } from 'lodash' 

Usage

updateData(newItem: any){
    let index = findIndex(this.data, {id: newItem.id});
    ...
  }

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment