Is there a limit on length of the key (string) in JS object?

前端 未结 3 1183
日久生厌
日久生厌 2020-11-28 06:50

So we had a case where we would have an object, where key is id (int) and the value is the string. But we noticed that most of the times, we look up id based on the string,

3条回答
  •  攒了一身酷
    2020-11-28 07:31

    No, there is no limit for the string length (as long as it fits into memory), and your implementation seems okay too. It's acutally quite common to have those 'turned around' arrays with e.g. boolean values. And as to the strings as keys: The strings are immutable symbols that are stored at a certain address, and what's actually used as the index for the array is that address (aka pointer aka reference) and not the string itself.

提交回复
热议问题