Frutis Frutis - 6 months ago 11
Javascript Question

How to deep clone this part of javascript?

still very new in js overall and i'm trying to deep clone this part of code.

$scope.add = function() {
$scope.data.push(Object.assign(mock));
};


If anyone could help me cloning this, would be grateful. Thanks

Answer

use angular's .copy() method to clone.

like this

$scope.data.push(angular.copy(mock));