回答編集履歴
1
チェック
answer
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
- [オブジェクトでの作業 - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Working_with_Objects)
|
|
2
2
|
|
|
3
3
|
にあるように、「オブジェクトは連想配列と呼ばれることがあります」ということですね。
|
|
4
|
-
ただしjsのオブジェクトはイテラブルではないので配列と呼ぶにはちょっと違和感があります。
|
|
4
|
+
ただしjsのオブジェクトはイテラブルではないので配列と呼ぶにはちょっと違和感があります。
|
|
5
|
+
|
|
6
|
+
なお、プリミティブな要素はそれぞれの型を参照できますが
|
|
7
|
+
```javascript
|
|
8
|
+
const bool=true;
|
|
9
|
+
const num=123;
|
|
10
|
+
const bint=123n;
|
|
11
|
+
const str="xyz";
|
|
12
|
+
const unde=undefined;
|
|
13
|
+
const func=()=>{};
|
|
14
|
+
console.log([typeof bool,typeof num,typeof bint,typeof str,typeof unde,typeof func]);
|
|
15
|
+
```
|
|
16
|
+
(ただしnullはオブジェクト)
|
|
17
|
+
オブジェクトやリスト系のもの配列などは型はobjectです
|
|
18
|
+
(数値や文字列もオブジェクト型で宣言すればobject)
|
|
19
|
+
```javascript
|
|
20
|
+
const o={};
|
|
21
|
+
const s=new Set();
|
|
22
|
+
const m=new Map();
|
|
23
|
+
const a=[];
|
|
24
|
+
const n=new Number();
|
|
25
|
+
const st=new String();
|
|
26
|
+
console.log([typeof o,typeof s,typeof m,typeof a,typeof n,typeof st]);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
ただし、厳密に型を比較することも可能です
|
|
30
|
+
```javascript
|
|
31
|
+
const o={};
|
|
32
|
+
console.log([o instanceof Object,o instanceof Array]);
|
|
33
|
+
const a=[];
|
|
34
|
+
console.log([a instanceof Object,a instanceof Array]);
|
|
35
|
+
```
|