-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
index.md
73 lines (50 loc) · 1.61 KB
/
index.md
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
---
title: Reflect.ownKeys()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys
---
{{JSRef}}
静的な **`Reflect.ownKeys()`** メソッドは、 `target` オブジェクトが持つプロパティキーの配列を返します。
{{EmbedInteractiveExample("pages/js/reflect-ownkeys.html")}}
## 構文
```
Reflect.ownKeys(target)
```
### 引数
- `target`
- : キーを取得する対象のオブジェクト
### 返値
`target` オブジェクトが持つプロパティキーの {{jsxref("Array")}} 。
### 例外
{{jsxref("TypeError")}}: `target` が {{jsxref("Object")}} ではない場合
## 解説
`Reflect.ownKeys` メソッドは、対象のオブジェクトが持つプロパティキーの配列を返します。この返値は、`{{jsxref("Object.getOwnPropertyNames", "Object.getOwnPropertyNames(target)", "", 1)}}.concat({{jsxref("Object.getOwnPropertySymbols", "Object.getOwnPropertySymbols(target)", "", 1)}})` と同じです。
## 例
### 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) ]
// 数字順のインデックス、
// 挿入順の文字列、
// 挿入順のシンボル
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- {{jsxref("Reflect")}}
- {{jsxref("Object.getOwnPropertyNames()")}}