質問編集履歴

2

タイトルの修正

2021/03/29 14:36

投稿

tennis
tennis

スコア19

test CHANGED
@@ -1 +1 @@
1
- jsで連想配列を作成したい
1
+ jsでオブジェクトの配列を作成したい
test CHANGED
File without changes

1

コードの修正

2021/03/29 14:36

投稿

tennis
tennis

スコア19

test CHANGED
File without changes
test CHANGED
@@ -4,27 +4,19 @@
4
4
 
5
5
  ```javascript
6
6
 
7
- let ary = [];
7
+ let items = []
8
8
 
9
+ for (let index = 0; index < 3; index++) {
9
10
 
11
+ let item = { name: "Apple", price: index }
10
12
 
11
- let item1 = {id:1,name:2};
13
+ items.push(item)
12
14
 
13
- ary.push(item1);
14
-
15
-
16
-
17
- let item2 = {id:2,name:2};
15
+ }
18
-
19
- ary.push(item2);
20
-
21
-
22
-
23
- console.log(ary)
24
16
 
25
17
  ```
26
18
 
27
- ![イメージ説明](e0503d26b05a4fb190114fe72c8615fa.png)
19
+ ![イメージ説明](ca53640e59671d5990fd53cf9abe0bd3.png)
28
20
 
29
21
 
30
22
 
@@ -44,23 +36,15 @@
44
36
 
45
37
  num.then((snapshot) => {
46
38
 
47
- snapshot.docs.forEach((doc) => {
39
+ snapshot.docs.forEach((doc) => {
48
40
 
49
- let hoge = {
41
+ let hoge = { id: doc.id, name: doc.data().name }
50
42
 
51
- id: doc.id,
43
+ huga.push(hoge)
52
44
 
53
- name: doc.data().name
45
+ })
54
46
 
55
- }
56
-
57
- huga.push(hoge)
58
-
59
- })
47
+ })
60
-
61
- })
62
-
63
- console.log(huga)
64
48
 
65
49
  ```
66
50