티스토리 뷰
반응형
자주는 아니지만 객체의 특정 컬럼의 중복을 제거를 해야할 때가 있다.
그럴때 나는 밑의 방법처럼 사용한다.
getGoodsCategoryInShopUsingGET(member_sq: number): Observable {
}
category:GoodsCategory= new GoodsCategory();
// 이런식으로
get this.mainCategory = Object(this.category).filter((array, index, self) => self.findIndex((t) =>
{ return t.mainCategoryName === array.mainCategoryName && t.mainCategoryId === array.mainCategoryId; }) === index );
// ! 주의Object(this.category)를처음에Array(this.category)로 사용했다가안되서낭패를봄
2. set을이용
this.mainCategory = Array.from(new Set(Object(this.category).map(name => name.mainCategoryName)));
// Array.from(new Set(Object(this.category).map(JSON.stringify))).map(JSON.parse);
다시객체로바꾸기 new Set(myData.map(JSON.stringify))은
new Set(myData.map(JSON.stringify))화 된 myData 요소를 사용하여 Set 객체를 만듭니다.
Set 객체는 모든 요소가 고유한지 확인합니다.
그런 다음 Array.from을 사용하여 만든 세트의 요소를 기반으로 배열을 만듭니다.
마지막으로 JSON.parse를 사용하여 문자열로 된 요소를 다시 객체로 변환합니다.
반응형
'FrontEnd > Angular' 카테고리의 다른 글
Event Binding의 종류 (0) | 2018.06.13 |
---|---|
template에 null 표현 (0) | 2018.06.13 |
NgModule (0) | 2018.06.07 |
angular 에서 jquery selector (0) | 2018.06.04 |
Angular 에서 jquery 및 JS사용법 (0) | 2018.06.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Router
- 페이스북 로그인
- Python
- React-router
- JPA
- python3
- Redux
- MySQL
- mobx
- data component module
- Spring Boot
- JavaScript
- https://www.tistory.com/auth/logout/
- localStorage
- react
- jQuery
- Java
- JSON
- data gird component
- data component
- data grid component
- CSS
- 파이썬3
- 파이썬
- data table component
- Spring
- angular router
- Angular
- facebook login
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함