Reflect.ownKeys()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
Reflect.ownKeys()
정적 메서드는 대상 객체의 자체 속성 키를 배열로 반환합니다.
시도해보기
const object1 = {
property1: 42,
property2: 13,
};
const array1 = [];
console.log(Reflect.ownKeys(object1));
// Expected output: Array ["property1", "property2"]
console.log(Reflect.ownKeys(array1));
// Expected output: Array ["length"]
구문
js
Reflect.ownKeys(target);
매개변수
target
-
자체 키를 가져올 대상 객체.
반환 값
주어진 객체의 자체 속성 키를 담은 Array
.
예외
설명
The Reflect.ownKeys()
메서드는 대상 객체의 자체 속성 키를 배열로 반환합니다. 반환 값은 Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target))
와 동일합니다.
예제
Reflect.ownKeys()
사용하기
js
Reflect.ownKeys({ z: 3, y: 2, x: 1 }); // [ "z", "y", "x" ]
Reflect.ownKeys([]); // ["length"]
var sym = Symbol.for("comet");
var sym2 = Symbol.for("meteor");
var obj = {
[sym]: 0,
str: 0,
773: 0,
0: 0,
[sym2]: 0,
"-1": 0,
8: 0,
"second str": 0,
};
Reflect.ownKeys(obj);
// [ "0", "8", "773", "str", "-1", "second str", Symbol(comet), Symbol(meteor) ]
// Indexes in numeric order,
// strings in insertion order,
// symbols in insertion order
명세
Specification |
---|
ECMAScript® 2025 Language Specification # sec-reflect.ownkeys |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ownKeys |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on 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.