Add elements to a list through a variable that changes by "for each"
Hello.
Please could you help me with the following code?
- data1 = map();
- data2 = map();
- all_data = list();
- item = map();
- all_items = list();
- data1 = {"name":"Jose", "age":"20"};
- data2 = {"name":"Maria", "age":"25"};
- all_data.add(data1);
- all_data.add(data2);
- for each i in all_data
- {
- item.clear();
- item.put("type","student");
- item.put(i);
- all_items.add(item);
- }
- info all_items;
The output is:
{"type":"student","name":"Maria","age":"25"},{"type":"student","name":"Maria","age":"25"}
But my expectation is as follows:
{"type":"student","name":"Jose","age":"20"},{"type":"student","name":"Maria","age":"25"}
Thank you very much in advance for your help.
José