欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JavaScriptJSON数组去重复Reduce

程序员文章站 2023-02-22 20:13:13
javascriptjson数组去重复reduce。 var arr = [{ "name": "zytx", &...

javascriptjson数组去重复reduce。

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);

JavaScriptJSON数组去重复Reduce