원

성능향상을 위한 팁-4

· 2010-06-30 (수) 11:27:56 · 2137 · 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,102
기타 10-11-09 조회 3,552
Flash 10-11-04 조회 2,254
기타 10-10-29 조회 3,013
JavaScript 10-10-29 조회 3,780
MySQL 10-10-27 조회 3,042
jQuery 10-10-24 조회 5,321
기타 10-10-23 조회 3,185
기타 10-10-22 조회 3,344
Flash 10-10-21 조회 2,521
MySQL 10-10-21 조회 3,266
Linux 10-10-19 조회 2,347
기타 10-10-19 조회 2,213
Flash 10-10-19 조회 3,684
기타 10-10-19 조회 2만
JavaScript 10-10-19 조회 2,360
기타 10-10-19 조회 2,417
기타 10-10-18 조회 3,772
기타 10-10-15 조회 1,829
기타 10-10-14 조회 3,297
Flash 10-10-12 조회 2,739
Flash 10-10-07 조회 2,393
JavaScript 10-10-07 조회 2,751
기타 10-10-06 조회 6,402
기타 10-10-05 조회 2,043
기타 10-10-05 조회 3,065
JavaScript 10-10-05 조회 9,115
정규표현식 10-10-05 조회 4,087
Flash 10-09-30 조회 4,540
기타 10-09-26 조회 3,621