You do not need jQuery for this task. Just Javascript. Jamiec gives the best answer, you can also use filter or reduce functions available for arrays.
filter function:
var numOfTrue = Answers.filter(function(item){ return item === "true"; }).length
Here you provide a callback function that runs for each element of the array. If this function returns true , then this element will be in the returned array. Then you get the length of this array (the length of the array ["true", "true"] is 2 )
reduction function:
var numOfTrue = Answers.reduce(function(counter, item){ return counter + (item === "true" ? 1 : 0); }, 0);
Reduce the function callback function that is executed for each element of the array. The array element is represented as the second argument, the first is the return value of the previously executed callback. The second argument to the decrease function is the initial value that is provided for the first callback function. If you omit this, then the first element from the array will be provided (in this example, if you forget to add 0 as the second argument, then the result value will be "true0010" string, because instead of adding numbers you will concatenate bites)
Mariusz pawelski
source share