码迷,mamicode.com
首页 > 编程语言 > 详细

数组中的json对象去重

时间:2018-03-21 13:49:02      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:bbb   log   hash   class   ret   return   ons   next   func   

数组中的json对象去重

var arr = [{
    "name": "ZYTX",
    "age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
    "gender": "AAAAAA.doc"
}, {
    "name": "ZYTA",
    "age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
    "gender": "BBBBBB.doc"
}, {
    "name": "ZDTX",
    "age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
    "gender": "CCCCCC.doc"
}, {
    "name": "ZYTX",
    "age": "Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix",
    "gender": "AAAAAA.doc"
}];
var hash = {}; arr = arr.reduce(function(item, next) { hash[next.name] ? ‘‘ : hash[next.name] = true && item.push(next); return item }, [])
console.log(arr);

 

数组中的json对象去重

标签:bbb   log   hash   class   ret   return   ons   next   func   

原文地址:https://www.cnblogs.com/sangzs/p/8616119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!