Saw this article How can i get most repeated value from Array in javascript
I am a newbie in jquery, I would like to know if how can I get the array values if it is declared inside an id or class div?
<p>#1 - Rate: <span class="score" id="score1"> 5</span></p>
<p>#2 - Rate: <span class="score" id="score2"> 5</span></p>
<p>#3 - Rate: <span class="score" id="score3"> 5</span></p>
<p>#4 - Rate: <span class="score" id="score4"> 5</span></p>
<p>#5 - Rate: <span class="score" id="score5"> 5</span></p>
This is the output looks like:
<div id="totalScore">55555</div>
I did this by getting the rates of 5 items
jQuery("#totalScore").append(jQuery(".list1").text());
In the article above the value is inside an array
var arr = [{
values: "Number of pips"
}, {
values: 4
}, {
values: 4
}, {
values: 4
}, {
values: 5
}, {
values: 2
}, {
values: 6
}, {
values: 6
}, {
values: 5
}];
var uniqs = {};
for (var i = 0; i < arr.length; i++) {
uniqs[arr[i].values] = (uniqs[arr[i].values] || 0) + 1;
}
var max = {
val: arr[0],
count: 1
};
for (var u in uniqs) {
if (max.count < uniqs[u]) {
max = {
val: u,
count: uniqs[u]
};
}
}
alert(max.val);
How to convert it like this? By getting only the value in id="totalScore" or .list1?