chromedude
chromedude

Reputation: 4302

Is there a limit to how long an item is in an array in javascript?

I am trying to figure out if I can store some strings in an array or if I need an object. Is there a limit to the number of characters allowed in an array item?

Upvotes: 3

Views: 2900

Answers (5)

Nicolas Repiquet
Nicolas Repiquet

Reputation: 9265

Arrays and objects in JavaScript are the same thing so the limits are the same.

Upvotes: 3

Ned Batchelder
Ned Batchelder

Reputation: 375982

Arrays in Javascript are really just specialized objects. There is no difference between what can be put into an array and what can be put into an object because an array is an object. The only difference is that arrays offer access methods based on integer indexes, can be created with [a,b,c] literals, and have a length member.

All memory in Javascript is dynamically allocated and automatically collected, so there are no limits on "the number of characters", other than the amount of RAM available to your program.

Upvotes: 0

fomicz
fomicz

Reputation: 1792

The maximum number of items is: 4 294 967 295 objects. Aarray item length is the same (4 294 967 295 symbols) :)

So you can have 4 294 967 295 objects 4 294 967 295 symbols each.

Hope it's clear. Cheers.

Upvotes: 1

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55519

In javascript the arrays function like a hashtable. So there is really no limit which you can set. You can have as many items in your array as possible, ofcourse if you can ignore memory constraint.

Upvotes: 1

Chinmayee G
Chinmayee G

Reputation: 8117

The exact maximum limit of an array is 2^32 - 1 or 4294967295, due to restrictions in Javascript's memory. The number of items, also known as the length property, cannot be greater than that. Check this for more details.

Upvotes: 5

Related Questions