blob: fceff9bdd92c4629a311ed62385c41bfb85d850b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
---
title: 'RangeError: repeat count must be non-negative'
slug: Web/JavaScript/Reference/Errors/Negative_repetition_count
tags:
- Error
- Errors
- JavaScript
- RangeError
translation_of: Web/JavaScript/Reference/Errors/Negative_repetition_count
---
<div>{{jsSidebar("Errors")}}</div>
<p>JavaScript の例外 "repeat count must be non-negative" は、 {{jsxref("String.prototype.repeat()")}} メソッドに <code>count</code> 引数が指定され、その値が負の数であった場合に発生します。</p>
<h2 id="Message">メッセージ</h2>
<pre class="brush: js">RangeError: argument out of range
RangeError: repeat count must be non-negative (Firefox)
RangeError: Invalid count value (Chrome)
</pre>
<h2 id="Error_type">エラータイプ</h2>
<p>{{jsxref("RangeError")}}</p>
<h2 id="What_went_wrong">エラーの原因</h2>
<p>{{jsxref("String.prototype.repeat()")}} メソッドを使用しています。 <code>count</code> 引数は、文字列の繰り返し回数を指定します。 これは 0 から正の {{jsxref("Infinity")}} 未満の値である必要があり、負の数は使用できません。 有効値の範囲は [0, +∞) のように説明できます。</p>
<h2 id="Examples">例</h2>
<h3 id="Invalid_cases">無効なケース</h3>
<pre class="brush: js example-bad">'abc'.repeat(-1); // RangeError </pre>
<h3 id="Valid_cases">有効な場合</h3>
<pre class="brush: js example-good">'abc'.repeat(0); // ''
'abc'.repeat(1); // 'abc'
'abc'.repeat(2); // 'abcabc'
'abc'.repeat(3.5); // 'abcabcabc' (count は整数に変換されます)
</pre>
<h2 id="See_also">関連情報</h2>
<ul>
<li>{{jsxref("String.prototype.repeat()")}}</li>
</ul>
|