Tell me how to correctly know which elements and how many times they repeat and if there are elements that are not repeated, too, to find out which one of the elements does not repeat ... say if there is such a data set:

["vasa", "peta", "vasa", "serega", "vasa", "andrey", "dima", "dima", "sveta", "oleg", "oleg", "oleg", "oleg", "igor", "vasa", "stas", "stas", "oleg", "serega", "serega", "andrey", "mihail", "volandemort"] 
  • In which language? - post_zeew
  • one
    @post_zeew - in Russian, this is Russian StackOverflow. - Igor
  • @ user3319778 What does it mean to “know correctly” compared to “know” which elements and how many times they repeat? - Vlad from Moscow
  • @post_zeew Judging by the author’s profile, either on JS or on jQuery. - Vlad from Moscow

1 answer 1

 var data = ["vasa", "peta", "vasa", "serega", "vasa", "andrey", "dima", "dima", "sveta", "oleg", "oleg", "oleg", "oleg", "igor", "vasa", "stas", "stas", "oleg", "serega", "serega", "andrey", "mihail", "volandemort"]; var result = {}; for(var iter = 0; iter < data.length; iter++) { var count = result[data[iter]]; if (count) { result[data[iter]] = count + 1; } else { result[data[iter]] = 1; } } console.log(result); 

Elements with counter 1 are not repeated.