티스토리 뷰

728x90

JSON에서 원하는 값을 parsing 한 후에 중복 값 제거하기

const myArray = [
	{ "id" : "1", "name" : "sskim", "country" : "korea" },
	{ "id" : "2", "name" : "lsy", "country" : "usa" },
	{ "id" : "3", "name" : "lsw", "country" : "canada" },
	{ "id" : "1", "name" : "sskim", "country" : "korea" },
	{ "id" : "5", "name" : "nyw", "country" : "australia" },
	{ "id" : "5", "name" : "kjh", "country" : "italia" }
];

const unique = myArray.map(function (val, index) {
	return val['id'];
}).filter(function (val, index, arr) {
	return arr.indexOf(val) === index;
});

console.log(unique);

결과 값

 

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
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
글 보관함