Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- SSE
- Partition
- mariadb
- EventSource
- node.js
- partitioning
- 실시간알림
- 개발자
- PostgreSQL
- Lag
- localStorage
- ServerSentEvent
- frontend
- 성장기
- Node.js기본
- node.js란
- 파티셔닝
- 열공하자
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[JS Level up][Ch2][데이터 실습] Lodash 사용법 본문
https://lodash.com/docs/4.17.15 Document 확인
.uniqBy(Array, Text)
Text를 기준으로 배열의 중복 제거
.unionBy(Array1, Array2, Text)
Array1, Array2 두 개의 배열을 병합하고 Text를 기준으로 중복 제거
import _ from 'lodash'
const usersA = [
{ userId : '1', name : 'SEARCHKIM'},
{ userId : '2', name : 'Neo'}
]
const usersB = [
{ userId : '1', name : 'SEARCHKIM'},
{ userId : '3', name : 'Amy'}
]
const usersC = usersA.concat(usersB); // 배열 병합
console.log('concat', usersC);
console.log('uniqBy', _.uniqBy(usersC,'userId')); // userId 중복 제거 -> userId가 고유한 값만 반환
const usersD = _.unionBy(usersA, usersB, 'userId'); // 두개의 배열을 합치고 userId가 고유한 값만 반환
console.log('unionBy', usersD);
.find(Array, 검색할 객체 데이터 )
Array에서 검색할 객체 데이터에 해당되는 객체 반환
.findIndex(Array, 검색할 객체 데이터 )
Array에서 검색할 객체 데이터에 해당되는 객체 인덱스 반환
.remove(Array, 삭제할 객체 데이터 )
Array에서 객체 데이터에 해당되는 객체 삭제
import _ from 'lodash'
const users = [
{ userId : '1', name : 'SEARCHKIM'},
{ userId : '2', name : 'Neo'},
{ userId : '3', name : 'Amy'},
{ userId : '4', name : 'Evan'},
{ userId : '5', name : 'Lewis'}
]
const foundUser = _.find(users, { name : 'Amy'} ); // users에서 name이 Amy인 객체 데이터 찾기
const foundUserIndex = _.findIndex(users, { name : 'Amy' }); // users에서 name이 Amy인 객체의 인덱스번호 찾기
console.log(foundUser);
console.log(foundUserIndex);
_.remove(users, {name : 'SEARCHKIM'}); // users에서 name이 SEARCHKIM인 객체 데이터 삭제
console.log(users);
'파도파도 나오는 JavaScript' 카테고리의 다른 글
[JS Level up][Ch2][데이터 실습] Storage (0) | 2022.02.04 |
---|---|
[JS Level up][Ch2][데이터 실습] JSON (0) | 2022.02.03 |
[JS Level up][Ch2][데이터 실습] 가져오기, 내보내기 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 얕은 복사와 깊은 복사 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 불변성 (0) | 2022.01.31 |
Comments