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()
メソッドは、 target
オブジェクトが持つプロパティキーの配列を返します。
試してみましょう
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"]
構文
Reflect.ownKeys(target)
引数
target
-
キーを取得する対象のオブジェクト
返値
target
オブジェクトが持つプロパティキーの Array
。
例外
解説
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"]
let sym = Symbol.for("comet");
let sym2 = Symbol.for("meteor");
let 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) ]
// 数字順のインデックス、
// 挿入順の文字列、
// 挿入順のシンボル
仕様書
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.