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
|
---
title: Array.prototype.toString()
slug: Web/JavaScript/Reference/Global_Objects/Array/toString
tags:
- Array
- JavaScript
- Method
- Prototype
translation_of: Web/JavaScript/Reference/Global_Objects/Array/toString
---
<div>{{JSRef}}</div>
<p><code><strong>toString()</strong></code> 메서드는 지정된 배열 및 그 요소를 나타내는 문자열을 반환합니다.</p>
<p>{{EmbedInteractiveExample("pages/js/array-tostring.html")}}</p>
<h2 id="구문">구문</h2>
<pre class="syntaxbox"><code><var>arr</var>.toString()</code></pre>
<h3 id="반환_값">반환 값</h3>
<p>배열을 표현하는 문자열을 반환합니다.</p>
<h2 id="설명">설명</h2>
<p>{{jsxref("Array")}} 객체는 {{jsxref("Object")}}의 <code>toString</code> 메서드를 재정의(override)합니다. Array 객체에 대해, <code>toString</code> 메서드는 배열을 합쳐(join) 쉼표로 구분된 각 배열 요소를 포함하는 문자열 하나를 반환합니다. 예를 들어, 다음 코드는 배열을 생성하며 그 배열을 문자열로 변환하기 위해 <code>toString</code>을 사용합니다.</p>
<pre class="brush: js">var monthNames = ['Jan', 'Feb', 'Mar', 'Apr'];
var myVar = monthNames.toString(); // 'Jan,Feb,Mar,Apr'을 myVar에 할당.
</pre>
<p>JavaScript는 배열이 텍스트 값으로 표현되거나 배열이 문자열 연결(concatenation)에 참조될 때 자동으로 <code>toString</code> 메서드를 호출합니다.</p>
<h3 id="ECMAScript_5_의미">ECMAScript 5 의미</h3>
<p>JavaScript 1.8.5 (Firefox 4)부터, ECMAScript 제5판 의미(semantics)와 일치하는 <code>toString()</code> 메서드는 일반(generic) 메서드이므로 모든 객체에 사용될 수 있습니다. 객체가 <code>join()</code> 메서드가 있는 경우, 호출되어 그 값이 반환됩니다. 그렇지 않으면 {{jsxref("Object.prototype.toString()")}}가 호출되어 그 결과값이 반환됩니다.</p>
<h2 id="명세">명세</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">명세</th>
<th scope="col">상태</th>
<th scope="col">설명</th>
</tr>
<tr>
<td>{{SpecName('ES1')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>초기 정의. JavaScript 1.1에서 구현됨.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.4.4.2', 'Array.prototype.toString')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-array.prototype.tostring', 'Array.prototype.toString')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-array.prototype.tostring', 'Array.prototype.toString')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="브라우저_호환성">브라우저 호환성</h2>
<p>{{Compat("javascript.builtins.Array.toString")}}</p>
<h2 id="같이_보기">같이 보기</h2>
<ul>
<li>{{jsxref("Array.prototype.join()")}}</li>
<li>{{jsxref("Object.prototype.toSource()")}}</li>
</ul>
|