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 2016ë 9ì.
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® 2027 Language Specification> # sec-reflect.ownkeys> |