I have a structure that looks like this:
JavaScript
x
19
19
1
var set_2 = {
2
nameofSet : 'French greetings',
3
category: 'languages',
4
cards : [
5
{
6
front : 'bonjour',
7
back : 'dzien dobry'
8
},
9
{
10
front : 'bonne nuit',
11
back : 'dobranoc'
12
},
13
{
14
front : 'bon soir',
15
back : 'dobry wieczor'
16
}
17
]
18
}
19
I can iterate over them in a loop like this:
JavaScript
1
6
1
var cards = set_2.cards;
2
for (k = 0;k<cards.length;k++) {
3
var frontSide = cards[k].front;
4
var backSide = cards[k].back;
5
}
6
Do I assume correctly that in the cards array I have a couple of objects without names?
If so, how can I push more objects like that to the cards array without giving them names? I want to create those objects in a for loop.
Advertisement
Answer
I’m not sure what you mean by names, but you can push more objects into the array as such:
JavaScript
1
2
1
set_2.cards.push({front: 'front', back: 'back'});
2