lodash란

lodash는 자바스크립트 유틸리티 라이브러리로써

array, collection, date, number, object 등이 있으며, 데이터를 쉽게 다룰 수 있도록 도와준다.

(예를들면, 배열 안에 중복 값을 제거하기 / object 배열 안에 특정 값만 추출하기 등..)

특히, 자바스크립트에서 배열 안의 객체들의 값을 핸들링할때 유용하다.

자주 사용하는 lodash

  1. find
const users = [
  { 'user': 'joey',  'age': 32 },
  { 'user': 'ross',    'age': 41 },
  { 'user': 'chandler', 'age': 39 }
]

// Native
users.find(function (o) { return o.age < 40; })

// lodash
_.find(users, function (o) { return o.age < 40; })
_.find(function(o){~~~~}(users);

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ebb58398-7c8b-4d6c-aba3-e296108382f8/Untitled.png

2. filter
const numbers = [10, 40, 230, 15, 18, 51, 1221]       

_.filter(numbers, num => num % 3 === 0)
numbers.filter(num => num % 3 === 0)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fb00786f-1e87-4312-b6e9-d6f5e7db07e6/Untitled.png