Character limit of a javascript string variable

前端 未结 3 671
无人及你
无人及你 2021-02-19 00:36

Can JavaScript string store 100K characters? I\'ve written a script where a string from PHP is passed to a variable in JavaScript. It works fine when it is cut short to almost

3条回答
  •  不思量自难忘°
    2021-02-19 01:36

    The ECMAScript Standard ECMA-262 (6th Edition, June 2015) says

    6.1.4 The String Type

    The String type is the set of all ordered sequences of zero or more 16-bit unsigned integer values ("elements") up to a maximum length of 253-1 elements.

    So don't plan on using more than 9,007,199,254,740,991 or about 9 quadrillion characters. Of course, you should be prepared for systems which cannot allocate 18 PB chunks of memory, as this is not required for conforming ECMAScript implementations.

提交回复
热议问题