覆盖JavaScript中的数组 [英] Overwrite array in JavaScript

查看:108
本文介绍了覆盖JavaScript中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何覆盖(或先取消设置然后再设置)数组?似乎"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 (我只是希望它们具有相同的值).这些对象包含一个名为 items 的数组,该数组在 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 + ')');

很抱歉打扰您,我应该详细说明一下,但是代码分为多个文件和功能.无论如何,谢谢大家,现在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆