Array.of() 메서드는 인자의 수나 유형에 관계없이 가변 인자를 갖는 새 Array 인스턴스를 만듭니다.
Array.of()와 Array 생성자의 차이는 정수형 인자의 처리 방법에 있습니다. Array.of(7)은 하나의 요소 7을 가진 배열을 생성하지만 Array(7)은 length 속성이 7인 빈 배열을 생성합니다.
Array.of(7); // [7] Array.of(1, 2, 3); // [1, 2, 3] Array(7); // [ , , , , , , ] Array(1, 2, 3); // [1, 2, 3]
구문
Array.of(element0[, element1[, ...[, elementN]]])
매개변수
elementN- 배열을 생성할 때 사용할 요소.
반환 값
새로운 Array 객체.
설명
이 함수는 ECMAScript 2015 표준 일부입니다. 자세한 정보는 Array.of, Array.from 제안 사항과 Array.of 폴리필에서 확인하실 수 있습니다.
예제
Array.of(1); // [1] Array.of(1, 2, 3); // [1, 2, 3] Array.of(undefined); // [undefined]
폴리필
아래 코드를 다른 코드 이전에 포함하면 Array.of를 지원하지 않는 환경에서도 사용할 수 있습니다.
if (!Array.of) {
Array.of = function() {
return Array.prototype.slice.call(arguments);
};
}
명세
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.of' in that specification. |
Standard | Initial definition. |
| ECMAScript Latest Draft (ECMA-262) The definition of 'Array.of' in that specification. |
Draft |
브라우저 호환성
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
of | Chrome Full support 45 | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support Yes | Safari Full support 9 | WebView Android Full support Yes | Chrome Android Full support 39 | Firefox Android Full support 25 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 4.0 | nodejs Full support 4.0.0 |
Legend
- Full support
- Full support
- No support
- No support