3

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?

5 Answers 5

5

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.

Sign up to request clarification or add additional context in comments.

5 Comments

The question is how long an array item can be (specifically, String item contained in an array), not the max array size
@Manny: a string is an array of characters, so it should fall under the same rules.
Am i misunderstanding the question that the user wants to store an array of strings, not store its characters in the array? E.g. what is the limit of the number of characters in a String that I can store at index 0 of an array?
@Manny: I think the OP want to know how many items can be stored in an array. An array of strings would have the same limit on length as the strings in the array.
I see, in anyway the number is the same. I was just confused by the answer. Thanks!
3

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

Comments

1

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.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.