If I have to delete all the items in an array, what's the difference between using new Array
and length = 0
? In the example, apparently the result looks the same.
function MyCtrl($scope) {
$scope.arrayData = ["1", "2", "3"];
$scope.newArray1 = function(){
$scope.arrayData = new Array();
}
$scope.newArray2 = function(){
$scope.arrayData = [];
}
$scope.lengthZero = function(){
$scope.arrayData.length = 0;
}
$scope.populate = function(){
$scope.arrayData.push("1", "2", "3");
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-controller="MyCtrl">
Data:
</h2><br>
<ul>
<li ng-repeat="data in arrayData">{{data}}</li>
</ul>
<button ng-click="newArray1()">New Array - 1st method</button>
<button ng-click="newArray2()">New Array - 2nd method</button>
<button ng-click="lengthZero()">Length = 0</button>
<button ng-click="populate()">Populate</button>
</div>