aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/array/isarray/index.html
blob: 0a3a074a3d1d1de1248e61d71435c45cfcc95ffe (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
title: Array.isArray()
slug: Web/JavaScript/Reference/Global_Objects/Array/isArray
tags:
  - Array
  - ECMAScript 5
  - JavaScript
  - Method
  - Reference
  - polyfill
  - 자바스크립트
  - 폴리필
translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray
---
<div>{{JSRef}}</div>

<p><code><strong>Array.isArray()</strong></code> 메서드는 인자가 {{jsxref("Array")}}인지 판별합니다.</p>

<pre><code>Array.isArray([1, 2, 3]);  // true
Array.isArray({foo: 123}); // false
Array.isArray('foobar');   // false
Array.isArray(undefined);  // false</code>
</pre>

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

<pre class="syntaxbox"><code>Array.isArray(<var>obj</var>)</code></pre>

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

<dl>
 <dt><code>obj</code></dt>
 <dd>검사할 객체.</dd>
</dl>

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

<p>객체가 {{jsxref("Array")}}라면 <code>true</code>, 아니라면 <code>false</code>.</p>

<h2 id="설명">설명</h2>

<p>객체가 {{jsxref("Array")}}라면 <code>true</code>를 반환하고, 아니라면 <code>false</code>를 반환합니다.</p>

<p>자세한 정보는 <a href="http://web.mit.edu/jwalden/www/isArray.html">“Determining with absolute accuracy whether or not a JavaScript object is an array”</a>(자바스크립트 객체가 배열인지 정확히 판별하는 방법) 문서를 참조하세요.</p>

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

<pre><code>// 모두 true 반환
Array.isArray([]);
Array.isArray([1]);
Array.isArray(new Array());
Array.isArray(new Array('a', 'b', 'c', 'd'));
Array.isArray(new Array(3));
// Array.prototype은 스스로도 배열입니다
Array.isArray(Array.prototype);

// 모두 false 반환
Array.isArray();
Array.isArray({});
Array.isArray(null);
Array.isArray(undefined);
Array.isArray(17);
Array.isArray('Array');
Array.isArray(true);
Array.isArray(false);
Array.isArray({ __proto__: Array.prototype });</code></pre>

<h3 id="instanceof_vs_isArray"><code>instanceof</code> vs <code>isArray</code></h3>

<p><code>Array</code> 객체를 판별할 때, <code>Array.isArray</code><code>iframe</code>을 통해서도 작동하기 때문에 <code>instanceof</code> 보다 적합합니다.</p>

<pre><code>var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
xArray = window.frames[window.frames.length-1].Array;
var arr = new xArray(1,2,3); // [1,2,3]

// 올바른 Array 판별
Array.isArray(arr);  // true
// iframe을 통해서 작동하지 않기 때문에 올바르지 않은 방법
arr instanceof Array; // false</code>
</pre>

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

<p>아래 코드를 실행하면 지원하지 않는 환경에서도 <code>Array.isArray()</code>를 사용할 수 있습니다.</p>

<pre class="brush: js">if (!Array.isArray) {
  Array.isArray = function(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  };
}
</pre>

<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('ES5.1', '#sec-15.4.3.2', 'Array.isArray')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>초안. 자바스크립트 1.8.5 에 구현됨.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-array.isarray', 'Array.isArray')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>
    <p> </p>
   </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-array.isarray', 'Array.isArray')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

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

<div>{{Compat("javascript.builtins.Array.isArray")}}</div>

<h2 id="참고">참고</h2>

<ul>
 <li>{{jsxref("Array")}}</li>
</ul>