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 580 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,297
- 5
- 72
- 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
- 508
- 3
- 12
-2
In Javascript objects are always passed by reference unless you make a copy of it yourself.
Dimitri L.
- 3,894
- 1
- 14
- 17