@[TOC](js數(shù)組對象根據(jù)id去重)
# js數(shù)組對象根據(jù)id去重
## 例子
```javascript
var arr = [{
? ? ? key: '01',
? ? ? value: '樂樂'
? ? }, {
? ? ? key: '02',
? ? ? value: '博博'
? ? }, {
? ? ? key: '03',
? ? ? value: '淘淘'
? ? }, {
? ? ? key: '04',
? ? ? value: '哈哈'
? ? }, {
? ? ? key: '01',
? ? ? value: '樂樂'
? ? }];
? ? // 方法1:利用reduce方法遍歷數(shù)組,reduce第一個參數(shù)是遍歷需要執(zhí)行的函數(shù)姨涡,第二個參數(shù)是item的初始值
? ? var obj = {};
? ? arr = arr.reduce(function (item, next) {
? ? ? obj[next.key] ? '' : obj[next.key] = true && item.push(next);
? ? ? return item;
? ? }, []);
? ? console.log(arr)
```