Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the limit on the length of a javascript property?

Tags:

javascript

var obj = {
    'foo' : 'bar',
    'something very, very, very, very long' : 'baz'
};

Any limits on how long that property name can be?

like image 565
sprugman Avatar asked Jan 07 '11 17:01

sprugman


People also ask

What is the maximum length of a string in JavaScript?

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.

What is maximum size of variable in JavaScript?

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.

What is length in JavaScript?

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.

How long can a JSON key be?

The maximum length of a JSON type using a binary storage format is 16776192 bytes.


1 Answers

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 :)

like image 101
David Hedlund Avatar answered Oct 03 '22 23:10

David Hedlund