Content-Length: 252489 | pFad | http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Negative_repetition_count

RangeError: repeat count must be non-negative - JavaScript | MDN

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

RangeError: repeat count must be non-negative

信息

RangeError: repeat count must be non-negative (Firefox)
RangeError: Invalid count value (Chrome)

错误类型

RangeError

发生了什么?

代码中使用了 String.prototype.repeat()方法。它有一个计数参数,表示重复该字符串的次数。该参数必须在 0 及正 Infinity 之间,且不能为负数。该值的合法范围可以这样表示: [0, +∞)。

示例

无效的

js
"abc".repeat(-1); // RangeError

有效的

js
"abc".repeat(0); // ''
"abc".repeat(1); // 'abc'
"abc".repeat(2); // 'abcabc'
"abc".repeat(3.5); // 'abcabcabc' (count will be converted to integer)

See also









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Negative_repetition_count

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy