I am creating an array in a project on NodeJs. When I send the array to a function, it changes the main array even if I assign the data to a temporary variable and make changes in that temporary variable. But I don't want any changes to the main array.
function abc(data) {
console.log("1. " + data.text);
var tempss = data;
console.log("2. " + tempss.text);
tempss.text = 20;
console.log("3. " + data.text);
console.log("4. " + tempss.text);
}
let a = new Array();
a.text = 3;
abc(a);
console.log("5. " + a.text);
Result:
1. 3
2. 3
3. 20
4. 20
5. 20
What I want to do:
1. 3
2. 3
3. 3
4. 20
5. 3