$scope.itemarray = ['A', 'B', 'C'];
this will clear the array but the ui wont be updated.
$scope.itemarray = [];
this works fine! why?
$scope.itemarray.length = 0;
To check if an array is empty or not, you can use the . length property. The length property sets or returns the number of elements in an array. By knowing the number of elements in the array, you can tell if it is empty or not.
$scope.itemarray.length = 0;
<< this is correct. Length is read-write property.
$scope.itemarray = [];
<< this creates new empty array. If you have bindings to old itemarray, they may be lost. (Html binding like ng-if="itemarray[0]"
wont be lost)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With