aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/string/slice/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ko/web/javascript/reference/global_objects/string/slice/index.html')
-rw-r--r--files/ko/web/javascript/reference/global_objects/string/slice/index.html129
1 files changed, 129 insertions, 0 deletions
diff --git a/files/ko/web/javascript/reference/global_objects/string/slice/index.html b/files/ko/web/javascript/reference/global_objects/string/slice/index.html
new file mode 100644
index 0000000000..3bd23ace3b
--- /dev/null
+++ b/files/ko/web/javascript/reference/global_objects/string/slice/index.html
@@ -0,0 +1,129 @@
+---
+title: String.prototype.slice()
+slug: Web/JavaScript/Reference/Global_Objects/String/slice
+tags:
+ - 메소드
+ - 문자열
+ - 자바스크립트
+ - 프로토타입
+translation_of: Web/JavaScript/Reference/Global_Objects/String/slice
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>slice()</code></strong> 메소드는 문자열의 일부를 추출하면서 새로운 문자열을 반환합니다.</p>
+
+<p>{{EmbedInteractiveExample("pages/js/string-slice.html")}}</p>
+
+<h2 id="문법">문법</h2>
+
+<pre class="syntaxbox notranslate"><code><var>str</var>.slice(<var>beginIndex</var>[, <var>endIndex</var>])</code></pre>
+
+<h3 id="매개변수">매개변수</h3>
+
+<dl>
+ <dt><code>beginIndex</code></dt>
+ <dd>추출 시작점인 0부터 시작하는 인덱스입니다. 만약 음수라면, beginIndex는  <code>strLength(문자열 길이) + beginIndex</code>로 취급됩니다. (예를 들어 <code>beginIndex</code>가 -3이면 시작점은 <code>strLength - 3</code>).</dd>
+ <dd>만약 <code>beginIndex</code>가 <code>strLength</code> 보다 크거나 같은 경우, <code>slice()</code>는 빈 문자열을 반환합니다.</dd>
+ <dt><code>endIndex</code>{{optional_inline}}</dt>
+ <dd>0부터 시작하는 추출 종료점 인덱스로 그 직전까지 추출됩니다.  인덱스 위치의 문자는 추출에 포함되지 않습니다.</dd>
+ <dd>만약 <code>endIndex</code>가 생략된다면, <code>silce()</code>는 문자열 마지막까지 추출합니다. 만약 음수라면, endIndex는 <code>strLength(문자열 길이) + endIndex</code> 로 취급됩니다(예를 들어 <code>endIndex</code>가 -3이면 종료점은 <code>strLength - 3</code>).</dd>
+</dl>
+
+<h3 id="반환_값">반환 값</h3>
+
+<p>문자열의 추출된 부분을 담는 새로운 문자열이 반환됩니다.</p>
+
+<h2 id="설명">설명</h2>
+
+<p><code>slice()</code>는 문자열로부터 텍스트를 추출하고 새 문자열을 반환합니다. 문자열의 변경은 다른 문자열에 영향을 미치지 않습니다.</p>
+
+<p><code>slice()</code>는 <code>endIndex</code>를 포함하지 않고 추출합니다. <code>str.slice(1, 4)</code>는 두 번째 문자부터 네 번째 문자까지 추출합니다 (1, 2, 3 인덱스 문자).</p>
+
+<p><code>str.slice(2, -1)</code>는 세 번째 문자부터 문자열의 마지막에서 두 번째 문자까지 추출합니다.</p>
+
+<h2 id="예시">예시</h2>
+
+<h3 id="slice를_사용하여_새_문자열_생성하기"><code>slice()</code>를 사용하여 새 문자열 생성하기</h3>
+
+<p>아래 예시는 새 문자열을 생성하기 위해 <code>slice()</code>를 사용합니다.</p>
+
+<pre class="brush: js notranslate">var str1 = 'The morning is upon us.', // the length of str1 is 23.
+ str2 = str1.slice(1, 8),
+ str3 = str1.slice(4, -2),
+  str4 = str1.slice(12),
+ str5 = str1.slice(30);
+console.log(str2); // OUTPUT: he morn
+console.log(str3); // OUTPUT: morning is upon u
+console.log(str4); // OUTPUT: is upon us.
+console.log(str5); // OUTPUT: ""
+</pre>
+
+<h3 id="음수_인덱스로_slice_사용하기">음수 인덱스로 <code>slice()</code> 사용하기</h3>
+
+<p>아래 예시는 <code>slice()</code>에 음수 인덱스를 사용합니다.</p>
+
+<pre class="brush: js notranslate">var str = 'The morning is upon us.';
+str.slice(-3); // returns 'us.'
+str.slice(-3, -1); // returns 'us'
+str.slice(0, -1); // returns 'The morning is upon us'
+</pre>
+
+<p>아래의 예시는 시작 인덱스를 찾기 위해 문자열의 끝에서부터 역방향으로 <code>11</code>개를 세고 끝 인덱스를 찾기 위해 문자열의 시작에서부터 정방향으로 <code>16</code>개를 셉니다.</p>
+
+<pre class="brush: js notranslate"><code>console.log(str.slice(-11, 16)) // =&gt; "is u";</code></pre>
+
+<p>아래에서는 시작 인덱스를 찾기 위해 문자열의 처음부터 정방향으로 <code>11</code>개를 세고 끝 인덱스를 찾기 위해 끝에서부터 <code>7</code>개를 셉니다.</p>
+
+<pre class="brush: js notranslate"><code>console.log(str.slice(11, -7)) // =&gt; "is u";</code>
+</pre>
+
+<p>이 인수는 끝에서부터 5로 역순으로 계산하여 시작 인덱스를 찾은 다음 끝에서부터 1을 거쳐 끝 인덱스를 찾습니다.</p>
+
+<pre class="brush: js notranslate"><code>console.log(str.slice(-5, -1)) // =&gt; "n us";</code>
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table>
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.slice', 'String.prototype.slice')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype.slice', 'String.prototype.slice')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5.4.13', 'String.prototype.slice')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Initial definition. Implemented in JavaScript 1.2.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p>{{Compat("javascript.builtins.String.slice")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("String.prototype.substr()")}}</li>
+ <li>{{jsxref("String.prototype.substring()")}}</li>
+ <li>{{jsxref("Array.prototype.slice()")}}</li>
+</ul>