Errors: Resulting string too large
信息
RangeError: repeat count must be less than infinity and not overflow maximum string size (Firefox)
RangeError: Invalid count value (Chrome)
错误类型
RangeError
哪里出错了?
String.prototype.repeat()
方法已被使用。它有一个count
参数,指示重复字符串的次数。它必须在0到小于正数之间Infinity
,不能是负数。允许值的范围可以这样描述:[0,+∞)。
结果字符串也不能大于最大字符串大小,这在JavaScript引擎中可能会有所不同。在Firefox(SpiderMonkey)中,最大字符串大小是228 -1(0xFFFFFFF
)。
示例
无效的情况
'abc'.repeat(Infinity); // RangeError
'a'.repeat(2**28); // RangeError
有效的情况
'abc'.repeat(0); // ''
'abc'.repeat(1); // 'abc'
'abc'.repeat(2); // 'abcabc'
'abc'.repeat(3.5); // 'abcabcabc' (count will be converted to integer)
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com