While using array.push() to add values at the end of an array in angularjs will it create a deep copy of the pushed value inside the array or not.
Asked
Active
Viewed 619 times
3 Answers
2
No, you will be adding a reference to the original object to the array, not the value or a copy
var obj = { key: "value" }
var arr = [];
arr.push(obj);
obj === arr[0];
// true

Felipe Sabino
- 17,825
- 6
- 78
- 112
0
No, Deep copy can be done via angular.copy. For example.
var data = [{'name':'abc'}, {'name':'xyz'}];
var copiedOne = angular.copy(data);

Manish Singh
- 518
- 3
- 13
-2
In Javascript objects are always passed by reference unless you make a copy of it yourself.

Dimitri L.
- 4,499
- 1
- 15
- 19