I have an array that I put together in jQuery and I\'m wondering if there is a way that I could find the number of occurrences of a given term. Would I have better results i
If you have an array like this:
var arr = [1, 2, 3, 4, 3, 2, 1];
And set your target value:
var target = 1;
Then you can find the number of occurences of target using:
target
var numOccurences = $.grep(arr, function (elem) { return elem === target; }).length; // Returns 2