最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How many variables can a javascript array hold? - Stack Overflow

programmeradmin3浏览0评论

I have a javascript array that is dynamically populated. Example: Array name $testarr[] And I have a database that fills it with numbers like this $testarr[id]=number. As my database is constantly growing I need to know when the array will hit the roof and refuse to take any more variables

I have a javascript array that is dynamically populated. Example: Array name $testarr[] And I have a database that fills it with numbers like this $testarr[id]=number. As my database is constantly growing I need to know when the array will hit the roof and refuse to take any more variables

Share Improve this question asked Oct 19, 2011 at 19:21 DreamWaveDreamWave 1,9403 gold badges28 silver badges63 bronze badges 3
  • 6 I put it to you that if you need to store this much data in JavaScript, you're doing something wrong and you should use Ajax lookups or server side pagination instead. (Provided you're talking about JavaScript in a browser. of course) – Pekka Commented Oct 19, 2011 at 19:22
  • 1 How many million items do you want to put there? I don't think there is a hard limit (well, maybe 2^53), I think the browsers and puters have different points at which they'll crash. – Michael Stum Commented Oct 19, 2011 at 19:23
  • 1 possible duplicate of Maximum size of an Array in Javascript – No Results Found Commented Oct 19, 2011 at 19:27
Add a ment  | 

3 Answers 3

Reset to default 3

This is browser-specific, so you need to check with the browser documentation. There have actually been exploits that took advantage of this, as a large enough array would go beyond the maximum allowed to by the browser.

I believe your design is faulty, as if you need to hold this many variables in javascript, you should probably re-think your design.

EDIT: apparently there is a limit - 2^32 - 1 - but I believe you'll reach the limit imposed by the browser before you get to 2^32 - 1 elements in the array.

Apparently it is unlimited only by system memory, although the length property fails if indices get larger than 1073741822 according to this source of 1997.

You're not dealing with a limitation of the Array javascript object, you're dealing with the memory limitation of the browser/machine bo that is running your scripts.

发布评论

评论列表(0)

  1. 暂无评论