본문 바로가기
Front-End

[lodash] lodash 를 사용하는 이유?

by Judy 2021. 12. 28.
출처: https://lodash.com/

lodash

JavaScript의 인기있는 라이브러리 중 하나이며, array, collection, data 등 데이터의 필수적인 구조를 쉽게 다룰 수 있게끔 하는데에 사용함.

 

Javascript에서 배열 안의 객체들의 값을 핸들링(배열, 객체 및 문자열 반복/ 복수적인 함수 생성)할 때 유용하게 사용됩니다.

 

장점

ㅡ. (변수) 이런식으로 작성할 경우 lodash wrapper로 변수를 감싸게 되면서 해당 변수에 대한 chaining을 시작합니다.
_ 라는 기호를 이용해서 사용하기 때문에 명칭 또한 lodash가 된 것이죠.
그 외에 lodash를 사용하는 이유들은 다음과 같습니다.

  • 브라우저에서 지원하지 않는 성능이 보장되어있는 다양한 메소드를 가지고 있음.
  • 퍼포먼스 측면에서 native보다 더 나은 성능을 가짐.
  • npm이나 기타 패키지 매니저를 통해 쉽게 사용 가능.
  • Javascript의 코드를 줄여줌
  • 빠른 작업에 도움이 됨.

lodash Method

array Method

findIndex()

형식: _.findindex(array,[predicate=.indentity],[thisArg])
출력: index number
배열 내에서 원하는 index를 쉽게 구할 수 있습니다.

flatten()

형식: _.flatten(arraym[isDeep])
다차원 배열 내의 요소를 출력하는데 편리합니다.

remove()

형식: .remove(array, [predicate=.identity], [thisArg])
출력: 제거된 array
배열 내의 조건에 맞는 요소들을 제거한 후 반환해줍니다.

collection Method

every()

형식: .every(collection, [predicate=.identity], [thisArg])
출력: boolean 값
배열 안 요소들의 값들을 비교하고 분석하는데 용이합니다.

find()

형식: .find(collection, [predicate=.identity], [thisArg])
find()
는 조건을 만족하는 컬렉션에서의 첫번째 요소를 찾는 메소드입니다.

filter()

형식: .filter(collection, [predicate=.identity], [thisArg])
filter()
는 특정 조건을 만족하는 모든 요소를 추출하는 메소드입니다.

map()

형식: .map(collection, [iteratee=.identity], [thisArg])
출력: 계산 결과 배열함수를 실행하고 그 결과를 배열로 반환합니다. key값을 입력할 경우 해당 key값들만 간추려서 반환홥니다.

forEach()

형식: .forEach(collection, [iteratee=.identity], [thisArg])
배열의 값마다 함수를 실행시킬 때 용이하게 사용됩니다.

includes()

형식: _.includes(collection, target, [fromIndex=0])
출력: boolean
해당 collection에 target값이 있는지 판별해줍니다.

reduce()

형식: .reduce(collection, [iteratee=.identity], [accumulator], [thisArg])

 

 

 

 

 

 

 

'Front-End' 카테고리의 다른 글

[Git] git branch & naming  (1) 2022.01.16
Next.js  (0) 2022.01.10
[tailwind CSS] tailwind css v3.0.7 업데이트 내용  (0) 2021.12.24
[Naver] Engineering 2021  (0) 2021.12.22
[tailwind CSS] tailwindCSS 기초 셋팅  (0) 2021.12.16