sprugman
sprugman

Reputation: 19831

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

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

Any limits on how long that property name can be?

Upvotes: 30

Views: 4521

Answers (1)

David Hedlund
David Hedlund

Reputation: 129782

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

Upvotes: 32

Related Questions