J. Doe J. Doe - 1 year ago 62
Javascript Question

How is my array that I am not using getting updated?

Here is my function:

function RemoveOutputKeys(array){
var temp = array;
for(var object in temp){
delete temp[object]['statusCode']
delete temp[object]['statusResponse']
if(temp == array)
console.log("how is this possible?!?!!?!?!")
return temp

and here is the input I am providing,

array = [{'statusCode':400},{'statusCode':200}]

It makes sense for
to get updated but I don't want the
to get updated. How can i fix this issue?


Answer Source

If you want create new array instead of alias/reference use:

var newArray = oldArray.slice();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download