When it comes to tasks like this, I find myself needing to handle situations like the following:
$scope.my_array = [];
var obj;
for (var i = 0; i < data.length; i++) {
obj = {};
obj.item1 = data.something;
obj.item2 = data.somethingElse;
$scope.my_array.push(obj);
}
Would it be more efficient to do this instead:
var my_array = [];
var obj;
for (var i = 0; i < data.length; i++) {
obj = {};
obj.item1 = data.something;
obj.item2 = data.somethingElse;
my_array.push(obj);
}
$scope.my_array = my_array;
I suspect that in the first version, the digest cycle may run every time an object is added to the array, unlike in the second version. Can you confirm if this is correct? Essentially, what would be the optimal way to approach the task mentioned above?