I have this code
var sections = [];
sections.add({'name': 'test', 'qustions' : []});
sections[0]['qustions'] = {'asd':'qustions 1'};
sections[0]['qustions'] = {'name':'qustions 2'};
print(sections);
returns
[{name: test, qustions: {name: qustions 2}}]
I want it to returns something like
[{name: test, qustions: [{name: qustions 1},{name: qustions 2}]}]
2
Answers
Every time you use
map[key]=newValue
, it reset the value for that key. what you need here is to performadd
for list.You may also like to create model class.
you can use
insert
method:output