New task: drop-down box to remove duplicate data
//Remove the front-end object array according to a certain attribute
The jsonArray is the one you want to duplicate array of objects.
Recommended tutorial: js tutorial
In the example, duplicates are removed according to the name attribute, as follows:
//前端对象数组 按某个属性去重 var obj = {}; jsonArray = jsonArray.reduce(function(item,next){ obj[next.name]?'':obj[next.name] = true&&item.push(next); return item; },[]); for(var i= 0;i<jsonArray.length;i++){ console.log(jsonArray[i]) }
Verify whether a certain attribute in the object array exists Repeat
Check the double if loop in the array object array to check whether the identityid2 attribute is repeated
if(json[i][key].length>0){ var array = json[i][key]; for(var x =0 ;x<array.length;x++){ for(var y =0;y<array.length;y++){ if(array[x].identityid2 == array[y].identityid2 && x!=y){ sweetAlert("","待签结算合同"+ i +"中的未中标供应商的第" + (x+1) +"包的身份证号" + array[x].identityid2 + "被复用", "error"); return false; } } } }
The above is the detailed content of How to implement deduplication of array attributes and verify duplicate data in js. For more information, please follow other related articles on the PHP Chinese website!