var ORDER = {"Rows":[]};
var data = [];
data[0] = ["0","V",amount[a],valueThree,"","",prcat,"00001","",price,"",Descr];
var dataJSONstring = JSON.stringify(data);
ORDER.Rows[0] += dataJSONstring;
嘿那里,我正在尝试将Javascript数据数组作为数组放入JSON“Rows”数组中。我试图将其字符串化,但每当我这样做时确实将它放入JSON数组中,但返回:**
undefined[["","V","2","90000001","","","0001","00001","","12","","Volwassenen"]]
如何删除“未定义”?无法找到如何做到这一点,任何想法?
答案 0 :(得分:0)
它返回undefined + string,这是我不理解的
因为ORDER.Rows[0]
未定义。您已将Rows
设置为空数组。它在索引0处没有条目。因此,检索该条目会为您提供undefined
,当您通过+
将其与字符串连接时,将转换为"undefined"
(加上字符串)。
请注意,a += b
实际上是a = a + b
(但未评估a
两次)。所以你的代码实际上是
ORDER.Rows[0] = ORDER.Rows[0] + dataJSONstring;
如果你想在那里存储字符串,你不想要+=
,只需要=
:
ORDER.Rows[0] = dataJSONstring;