🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 基本使用 ![mark](http://qiniu.newthink.cc/blog/20171123-110232777.png) ## 代码 ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.js"></script> <title>Title</title> </head> <body> <div id="test">click</div> <script> var paylist = [ {"id":"1","paymode": '1', "payname": "现金", "paymoney": "20"} , {"id":"3","paymode": '2', "payname": "支付宝", "paymoney": "50"} , {"id":"2","paymode": '1', "payname": "现金", "paymoney": "40"} ]; //去重 var newPaylist = uniqueArray(paylist,'payname'); //形成新结构 $("#test").html(""); $.each(newPaylist,function(index,item){ var html = ''; html += '<span>'+item.payname+'</span><br/>'; $("#test").append(html); }); /* * JSON数组去重 * @param: [array] json Array * @param: [string] 唯一的key名,根据此键名进行去重 */ function uniqueArray(array, key) { var result = [array[0]]; for (var i = 1; i < array.length; i++) { var item = array[i]; var repeat = false; for (var j = 0; j < result.length; j++) { if (item[key] == result[j][key]) { repeat = true; break; } } if (!repeat) { result.push(item); } } return result; } </script> </body> </html> ```