javascriptarraysoverwriteunset

How to overwrite an array?


How do I overwrite (or unset and then set) an array? Seems like "array = new_array" doesn't work.


Solution

  • Hm, it seems like the problem wasn't what I thought; my mistake was the following rows, which after all havn't got anything to do with arrays at all:

    sms.original = eval('(' + data + ')');
    sms.messages = sms.original;
    

    sms.original becomes an object, and then sms.messages becomes sms.original (I just wanted them to have the same value). The objects contain an array named items which was ment to remain static in the sms.original object, but when I changed sms.messages the original object changed as well. The solution was simple:

    sms.original = eval('(' + data + ')');
    sms.messages = eval('(' + data + ')');
    

    Sorry for bothering you, I should have elaborated but the code is splited in multiple files and functions. Thank you guys anyway, now does Guffa's splice technique work for me.