var obj = {
'foo' : 'bar',
'something very, very, very, very long' : 'baz'
};
Any limits on how long that property name can be?
Max length of a JavaScript string According to ECMAScript specification a string cannot contain more than 9,007,199,254,740,991 (2⁵³-1) characters.
JavaScript imposes a limit of 254 characters for each string variable assignment in your program. If you go over the 254-character limit, JavaScript responds with a "Unterminated string literal" error message.
length is a property of arrays in JavaScript that returns or sets the number of elements in a given array. The length property of an array can be returned like so.
The maximum length of a JSON type using a binary storage format is 16776192 bytes.
From my briefest empirical studies, there is no limit enforced by javascript, at least not as implemented by Chrome. It is simply a question of how much memory your machine allows the script engine to consume before the application crashes.
During my tests, a managed to create an object containing a property with a 268 435 456 chars long name, but trying again at 536 870 912, my browser crashed.
I don't believe it would be of any interest to find where my threshold is with any greater accuracy than that, since this should prove that any limits that are there, are entirely imposed by the capacity of the machine, rather than by specs.
Oh, and at 67 108 864 chars, I started noticing performance issues when assigning properties :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With