성능향상을 위한 팁-4 정보
기타 성능향상을 위한 팁-4본문
큰 오브젝트 리스트의 빠른 탐색을 위한 해쉬테이블 형태 사용
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에서 이동 됨]
추천
0
0
댓글 1개
오타가 있는것 같은데...
for문에 새로운 배열 만들어주는거 score가 아니라 sales[score[i]....
for문에 새로운 배열 만들어주는거 score가 아니라 sales[score[i]....