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);
下一篇: photoshop设计制作木箱子图标
推荐阅读