-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
65 lines (41 loc) · 1.89 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
---
title: Object.getOwnPropertySymbols()
slug: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols
l10n:
sourceCommit: 892e4301623f10505dc19e56ba9fb7b505530722
---
{{JSRef}}
**`Object.getOwnPropertySymbols()`** 静的メソッドは、与えられたオブジェクト上で直接見つかるシンボルプロパティすべての配列を返します。
{{EmbedInteractiveExample("pages/js/object-getownpropertysymbols.html")}}
## 構文
```js-nolint
Object.getOwnPropertySymbols(obj)
```
### 引数
- `obj`
- : シンボルプロパティが返されるオブジェクトです。
### 返値
与えられたオブジェクト上で直接見つかるシンボルプロパティすべての配列です。
## 解説
{{jsxref("Object.getOwnPropertyNames()")}} と同様、与えられたオブジェクトのすべてのシンボルプロパティをシンボルの配列として取得することができます。 {{jsxref("Object.getOwnPropertyNames()")}} 自体はオブジェクトのシンボルプロパティを含まず、文字列プロパティのみを含むことに注意して下さい。
すべてのオブジェクトが最初に自身のシンボルプロパティを持っているとは限らないので、 `Object.getOwnPropertySymbols()` は、オブジェクトにシンボルプロパティを設定しない限りは空の配列を返します。
## 例
### getOwnPropertySymbols の使用
```js
var obj = {};
var a = Symbol("a");
var b = Symbol.for("b");
obj[a] = "localSymbol";
obj[b] = "globalSymbol";
var objectSymbols = Object.getOwnPropertySymbols(obj);
console.log(objectSymbols.length); // 2
console.log(objectSymbols); // [Symbol(a), Symbol(b)]
console.log(objectSymbols[0]); // Symbol(a)
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- {{jsxref("Object.getOwnPropertyNames()")}}
- {{jsxref("Symbol")}}