我有以下代碼輸出陣列的長度,將其刪除,然後輸出的新長度:爲什麼刪除後該數組仍然具有非零長度?
console.log($scope.adviceList.activeAdvices.length); // *1*
$scope.adviceList.activeAdvices.splice(id,1); // *id is a parameter*
console.log($scope.adviceList.activeAdvices.length); // *0*
console.log($scope.adviceList.activeAdvices.length); // *1*
delete $scope.adviceList.activeAdvices[id];
console.log($scope.adviceList.activeAdvices.length); // *0*
console.log($scope.adviceList.activeAdvices); // *[]*
刪除之後,該陣列被正確地顯示爲空。然而,它的長度仍然是1.
這些變量在哪裏聲明? –
請參閱http://stackoverflow.com/questions/500606/javascript-array-delete-elements中的第一個答案 – tsiki
可能的重複[Javascript對象與數組,刪除它實際上是否刪除該項目?](http:// stackoverflow。 com/questions/495764/javascript-object-with-array-deleting-do-it-actually-remove-the-item) – tsiki