aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/string/startswith/index.html
blob: 19fce8ea97a9aa597980598d9fa3212846990022 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
title: String.prototype.startsWith()
slug: Web/JavaScript/Reference/Global_Objects/String/startsWith
tags:
  - ECMAScript 2015
  - JavaScript
  - Method
  - Prototype
  - Reference
  - String
translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith
---
<div>{{JSRef}}</div>

<p><span class="seoSummary"><strong><code>startsWith()</code></strong></span><span class="seoSummary"> 메소드는 어떤 문자열이 특정 문자로 시작하는지 확인하여 결과를 <code>true</code> 혹은 <code>false</code>로 반환합니다.</span></p>

<h2 id="구문">구문</h2>

<pre class="syntaxbox"><var>str</var>.startsWith(<var>searchString</var>[, <var>position</var>])</pre>

<h3 id="매개변수">매개변수</h3>

<dl>
 <dt><code>searchString</code></dt>
 <dd>문자열의 시작 지점에서 탐색할 문자열</dd>
 <dt><code>position</code> {{optional_inline}}</dt>
 <dd><code>searchString</code>을 탐색할 위치. 기본값 0.</dd>
</dl>

<h3 id="반환_값">반환 값</h3>

<p>문자열이 검색 문자열로 시작하면 <code>true</code>, 아니면 <code>false</code>.</p>

<h2 id="설명"><span class="hidden"> </span><span class="hidden"> </span>설명</h2>

<p><code>startsWith</code> 메소드로 어떤 문자열이 다른 문자열로 시작하는지 확인 할 수 있습니다. 대소문자를 구분합니다.</p>

<h2 id="예시">예시</h2>

<h3 id="startsWith()_사용하기"><code>startsWith()</code> 사용하기</h3>

<pre class="brush: js">//startswith
var str = 'To be, or not to be, that is the question.';

console.log(str.startsWith('To be'));         // true
console.log(str.startsWith('not to be'));     // false
console.log(str.startsWith('not to be', 10)); // true
</pre>

<h2 id="폴리필">폴리필</h2>

<p><code>startsWith</code> 메소드는 ECMAScript 2015 명세에 포함됐으며, 아직까지 모든 JavaScrpt 구현체가 지원하지 않을 수 있습니다. 그러나 아래 코드 조각을 사용해 폴리필 할 수 있습니다.</p>

<pre><code>if (!String.prototype.startsWith) {
	String.prototype.startsWith = function(search, pos) {
		return this.substr(!pos || pos &lt; 0 ? 0 : +pos, search.length) === search;
	};
}</code></pre>

<p>ES2015 명세를 모두 만족하지만, 더 무거운 폴리필은 <a href="https://github.com/mathiasbynens/String.prototype.startsWith">Mathias Bynens의 GitHub</a> 에서 확인할 수 있습니다.</p>

<h2 id="명세서">명세서</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="브라우저_호환성">브라우저 호환성</h2>

<div>{{Compat("javascript.builtins.String.startsWith")}}</div>

<h2 id="관련_문서">관련 문서</h2>

<ul>
 <li>{{jsxref("String.prototype.endsWith()")}}</li>
 <li>{{jsxref("String.prototype.includes()")}}</li>
 <li>{{jsxref("String.prototype.indexOf()")}}</li>
 <li>{{jsxref("String.prototype.lastIndexOf()")}}</li>
</ul>