JavaScript的:覆盖阵列 [英] JavaScript: Overwrite array
问题描述
我如何覆盖(或撤消,然后设置)数组?好像数组= new_array是行不通的。
How do I overwrite (or unset and then set) an array? Seems like "array = new_array" doesn't work.
感谢您提前。
推荐答案
嗯,好像问题不是我的想法;我的错误是以下行,它毕竟没有带什么东西都做数组:
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 的变成了一个对象,然后的 sms.messages 的变的 sms.original 的(我只是想要他们具有相同的值)。该对象包含一个名为阵列的项目的这是彪留在 sms.original 的对象静态的,但是当我改变的 sms.messages 的原对象改变了。解决的办法很简单:
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 + ')');
很抱歉打扰你,我应该已经制定,但code是多个文件和功能splited。谢谢你们反正现在确实Guffa的拼接技术,为我工作。
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.
这篇关于JavaScript的:覆盖阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!