如何实现数组去重?

arr=[{'name':'json'},{"idname":'tom'},{'idname':'bim'},{'name':'json'}];
function removearr(){
arr1=[];}
//不会往下做了;求教大神帮忙

Cats萌萌
浏览 638回答 1
1回答

回首忆惘然

&nbsp;var result = {};var arr1 = [];for(let i=0;i<arr.length;i++){if(result[JSON.stringify(arr[i])]){&nbsp; &nbsp;&nbsp;&nbsp; }else{&nbsp; &nbsp; result[JSON.stringify(arr[i])] = true;&nbsp; &nbsp; arr1.push(arr[i]);&nbsp; }}&nbsp;console.log(arr1);`
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript