본문 바로가기
프로그래밍

2023-05-16 javascript_array

by AandBB 2023. 5. 16.
let voteCounter = {};
/*let i=0;
let j=0;*/

for (let name of votes) {
  
  /*if(name==='이재식'){
    voteCounter[name]=++i;
  }else{
    voteCounter[name]=++j;
  }*/
  
  if(name in voteCounter){
    voteCounter[name]=voteCounter[name]+1;
  }else{
    voteCounter[name]=1;
  }
}

We don't have to define variable i and j, if we use the second codes not the first codes.

'프로그래밍' 카테고리의 다른 글

2023-06-15 html  (0) 2023.06.16
2023-06-13 javascript_string  (0) 2023.06.13
2023-05-13 javascript  (0) 2023.05.13
2023-05-11 javascript  (0) 2023.05.11
2023-05-08 javascript  (0) 2023.05.08