This question regarding javascript language. Simply think we have a map and we insert item as following manner
var dataMap=new Map();
//First Mechanism
//firstly we can think of structure of values of map can be JSONArray of objects
dataMap.set("key1",[{'id':12,'name':"obj1"}]); // init
// and,then insert new element to JSON Array which holds by map using 'key1'
dataMap.get("key1").push({'id':23,'name':"obj47"});//updated, now value of 'key1' is an JSON array which holds two elements
// expect 'key1' -> [{'id':12,'name':"obj1"},{'id':23,'name':"obj47"}]
//Second mechanism
// next we cant think of structure of values of map as JSONObject of Arrays
dataMap.set("key1",{'id':[12],'name':["obj1"]}); // init
// then we proceed with update operations like this
dataMap.get("key1").id.push(23);
dataMap.get("key1").name.push("obj47"); // two operations to insert items to respective arrays.
// expect 'key1' ->{'id':[12,23],'name':["obj1","obj47"]}
Which approach is most effective and efficient?
Think we have considerable amount of insertion operations to map ,if we are in to performance which one is better?
(If I have done mistake please correct ,I wanted to simplify the question as possible as I can that's why) Thank you.