回答編集履歴

6

a

2018/04/27 01:16

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- で説明する問題があるため、ナシだと思います。
5
+ で説明する問題があるため、ナシだと思います。
6
6
 
7
7
 
8
8
 

5

a

2018/04/27 01:16

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- ナシだと思います。
5
+ 以外で説明する問題があるため、ナシだと思います。
6
6
 
7
7
 
8
8
 

4

a

2018/04/27 01:15

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -82,13 +82,23 @@
82
82
 
83
83
  ```
84
84
 
85
- var arrNewUser = {};
85
+ let arrNewUser = {};
86
86
 
87
87
  arrNewUser['001'] = ['001', '小林'];
88
88
 
89
- console.log(arrNewUser) // { '001': [ '001', '小林' ] }
90
89
 
90
+
91
+ console.log(arrNewUser); // { '001': [ '001', '小林' ] }
92
+
91
- console.log(arrNewUser['001']) // [ '001', '小林' ]
93
+ console.log(arrNewUser['001']); // [ '001', '小林' ]
94
+
95
+
96
+
97
+ Object.keys(arrNewUser).forEach(function(key) {
98
+
99
+ console.log(arrNewUser[key]); // [ '001', '小林' ]
100
+
101
+ });
92
102
 
93
103
  ```
94
104
 
@@ -96,12 +106,24 @@
96
106
 
97
107
  ```
98
108
 
99
- var arrNewUser = new Map();
109
+ let arrNewUser = new Map();
100
110
 
101
111
  arrNewUser.set('001', ['001', '小林']);
102
112
 
103
- console.log(arrNewUser) // Map { '001' => [ '001', '小林' ] }
104
113
 
114
+
115
+ console.log(arrNewUser); // Map { '001' => [ '001', '小林' ] }
116
+
105
- console.log(arrNewUser.get('001')) // [ '001', '小林' ]
117
+ console.log(arrNewUser.get('001')); // [ '001', '小林' ]
118
+
119
+ console.log(arrNewUser.size); // 1
120
+
121
+
122
+
123
+ for (let user of arrNewUser.values()) {
124
+
125
+ console.log(user); // [ '001', '小林' ]
126
+
127
+ }
106
128
 
107
129
  ```

3

https://codepen.io/anon/pen/OZRgJO

2018/04/26 11:47

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -70,6 +70,12 @@
70
70
 
71
71
 
72
72
 
73
+ [https://codepen.io/anon/pen/OZRgJO
74
+
75
+ ](https://codepen.io/anon/pen/OZRgJO)
76
+
77
+
78
+
73
79
  というようにおかしな挙動になってしまうので、こういう場合は`Object`か`Map`を使うべきだと思います。
74
80
 
75
81
 

2

a

2018/04/26 11:35

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -50,11 +50,13 @@
50
50
 
51
51
  arrNewUser['001'] = ['001', '小林'];
52
52
 
53
- console.log(arrNewUser) // [ ] - 環境によっては空の配列にな(node環境確認)
53
+ console.log(arrNewUser) // [ ] - 環境によっては空の配列が表示されこともあるようす。
54
54
 
55
55
  console.log(arrNewUser.length); //0 - lengthは0
56
56
 
57
57
  arrNewUser.forEach(function(value, index) {
58
+
59
+ console.log('hello'); // 何も表示されない
58
60
 
59
61
  console.log(value, index); // 何も表示されない
60
62
 

1

a

2018/04/26 11:32

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  arrNewUser['001'] = ['001', '小林'];
52
52
 
53
- console.log(arrNewUser) // [ ] - 空の配列
53
+ console.log(arrNewUser) // [ ] - 環境によっては空の配列になる(node環境で確認)
54
54
 
55
55
  console.log(arrNewUser.length); //0 - lengthは0
56
56