我想比較,「項目」陣列和copyofOpList陣列中的項目copyofOpList從陣列比較它的其他陣列
檢索數據出現刪除數據,這是我嘗試:
var _deleteUsedElement1 = function(item) {
for (var i = 0; i < item.length-1; i++){
for (var j = 0; j< $scope.copyofOpList.length-1; j++){
if (item[i].operationCode == $scope.copyofOpList[j].code) {
$scope.copyofOpList.splice(j, 1);
} } } };
$scope.compareArrays = function() {
...Get data from web Service
_deleteUsedElement1(item);
}
copyofOpList數組有14個元素,而item數組有2個數組 但我的代碼只刪除了一個出現(第一個),所以請如何更正我的代碼,以檢索copyofOpList數組中的任何出現item array 感謝幫助
感謝先生的回覆:) – Jina
這就是非常優雅和簡潔。雖然我想指出它仍然在循環中循環,因爲indexOf()本身就是一個循環:) –
隨着您的編輯,這涵蓋了我的答案,所以我將刪除它。 – JonSG