i have two arrays, at the begining one is empty and i assign what is in the other to this empty array. Something like this. $scope.module_Allquestions = $scope.module_questions.questions;
What i need to know is if there is some way to break references between two arrays, i'm working in some project in angular js. So i know that in es6 we can you spread operator. But i was told that in angular js that is behind es6 i can't use it. Do you know any way on how to make those arrays not referenced?
Thanks.
CodePudding user response:
But i was told that in angular js that is behind es6 i can't use it
You were told wrong. Angular is just a JS library. You can use spread syntax if the JS engine you are running on supports it. (Which is basically "Anything except IE 11" and even then you can transpile it to ES5).
Other options include Array.from(scope.module_questions.questions)
and scope.module_questions.questions.slice()
for shallow copies and the Immer library for dealing with more complex data structures (such as when you have an array of objects).
CodePudding user response:
Depending on your contents, you could go for a copy strategy such as $scope.module_Allquestions = JSON.parse(JSON.stringify($scope.module_questions.questions));