我有此數組對象:如何檢查在陣列對象的值angularjs
$scope.datas.labels=['10','20','30']
並且還我有一個函數返回一個這樣的數組對象:
response.labels=['10','20','30','50','100','80']
我創建了一個函數,它接收最後的結果..但我想要的是檢查response.labels中的值是否存在$ scope.datas.labels我不想插入它..以避免在$ scope.datas.labels重複的數據,如何我能做到嗎?
我試過,但我沒有工作:
$scope.concatToData=function (response) {
if($scope.datas.labels=='') {
$scope.datas.labels = $scope.datas.labels.concat(response.labels);
}else {
var i;
for (i = 0; i < $scope.datas.labels.length; i++) {
alert('qa' + JSON.stringify($scope.datas.labels));
alert('res' + JSON.stringify(response.labels));
if ($scope.datas.labels[i] !== response.labels[i]) {
$scope.datas.labels = $scope.datas.labels.concat(response.labels[i]);
} else {
break;
}
}
}
$scope.datas.datasets = $scope.datas.datasets.concat(response.datasets);
}
的可能的複製[如何合併在Javascript兩個數組並刪除重複的項目](http://stackoverflow.com/questions/1584370/how-to-merge-two- array-in-javascript-and-de-duplicate-items) – PMerlet
謝謝你這樣做 –