javascript对象的最大大小限制为10000个字符 [英] javascript object max size limit at 10000 chars
问题描述
运行此代码时,变量项仅追加9999个字符,其余部分被截断.在上一篇文章中我得到了一些答案,但问题仍然存在.
When I run this code, the variable items only appends 9999 chars and rest is truncated. I got a few answers in the previous post but the problem still persists.
var items = [];
for (var i = 1; i < 400; i++) {
items.push('{"Key":' + '"this is a javascript value"' +
",'+'" + '"Value"' + ':' + '"this is value"}');
}
alert(items);
帮助!
推荐答案
您正在alert
设置该值,这意味着该数组将转换为String,然后置于警告框中.最有可能的是,字符串被截断为最大长度,否则出于图形原因,它就不会适合在屏幕上或框中.
You are alert
ing the value which means the array is converted to a String and then put in an alert box. Most probably, the String is cut off to some maximum length, otherwise it just won't fit on the screen or in the box for graphical reasons.
在内存中尝试并仅警告长度时,一切似乎都正常,toString()
也会返回正确的长度.我尝试了4000个元素并分析了长度: http://jsfiddle.net/LWD2h/1/.
When tried in-memory and only alerting the lengths, everything seems OK, also the toString()
returns the correct length. I tried 4000 elements and analyzing the lengths: http://jsfiddle.net/LWD2h/1/.
这篇关于javascript对象的最大大小限制为10000个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!