원

성능향상을 위한 팁-4

· 2010-06-30 (수) 11:27:56 · 2132 · 1
큰 오브젝트 리스트의 빠른 탐색을 위한 해쉬테이블 형태 사용

var score = [];
score[score.length] = {user:"u1", type:"left", total:230};
score[score.length] = {user:"u2", type:"right", total:215};

score[score.length] = {user:"u3", type:"right", total:283};
...

score[score.length] = {user:"u8", type:"left", total:370};
score[score.length] = {user:"u9", type:"left", total:198};

 

for (var i = 0; i < score.length; i++) {
    score[score[i].type + "_" + score[i].user] = score[i];
}

 

sales["right_u3"].total // 283

→ 전체를 탐색하지 않고 값에 직접 접근이 가능.

 

 

[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|

댓글 1개

오타가 있는것 같은데...
for문에 새로운 배열 만들어주는거 score가 아니라 sales[score[i]....
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
MySQL 10-11-13 조회 4,101
기타 10-11-09 조회 3,541
Flash 10-11-04 조회 2,254
기타 10-10-29 조회 3,009
JavaScript 10-10-29 조회 3,776
MySQL 10-10-27 조회 3,040
jQuery 10-10-24 조회 5,320
기타 10-10-23 조회 3,180
기타 10-10-22 조회 3,340
Flash 10-10-21 조회 2,515
MySQL 10-10-21 조회 3,261
Linux 10-10-19 조회 2,346
기타 10-10-19 조회 2,212
Flash 10-10-19 조회 3,682
기타 10-10-19 조회 2만
JavaScript 10-10-19 조회 2,356
기타 10-10-19 조회 2,415
기타 10-10-18 조회 3,755
기타 10-10-15 조회 1,826
기타 10-10-14 조회 3,293
Flash 10-10-12 조회 2,736
Flash 10-10-07 조회 2,392
JavaScript 10-10-07 조회 2,746
기타 10-10-06 조회 6,399
기타 10-10-05 조회 2,042
기타 10-10-05 조회 3,065
JavaScript 10-10-05 조회 9,114
정규표현식 10-10-05 조회 4,087
Flash 10-09-30 조회 4,534
기타 10-09-26 조회 3,619