자바 스크립트 언어에 관한이 질문. 은 간단하게 우리가지도를 가지고 우리가 가장 효과적이고 효율적인 방법 배열의 JS 개체 대 JS 개체의 배열 효율적이고 성능
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"]}
방식
다음과 같은 항목을 삽입 생각?지도으로 상당한 삽입 작업이 있다고 생각하면 실적이 좋으면 더 좋을까요?
(내가 잘못 입력 한 경우 수정하십시오. 그 이유는 최대한 간단하게 처리하고 싶습니다.) 감사합니다.
두 방법 모두 결과가 다르므로 나중에이 배열을 어떻게 사용할 것인지에 따라 달라집니다. – gurvinder372
@ gurvinder372 그게 내가 전에 생각한 것입니다. 그러나 각 접근법의 성과를 결정하는 방법은 무엇입니까? – Buddhika
@Buddhika : 성능 문제가 아닙니다. 그것은 당신에게 더 사용하기 쉬운 것에 달려 있습니다. 그리고 그것은 ___Primarily Opinion-Based입니다 .____ – Cerbrus