Counting occourences of a variable in an array filled with objects in JavaScript / Angular -
lets have array filled objects this:
{conversation_id: 38 id: 99 is_seen: 1 message: "hej kristina" timestamp: "2015-07-08t10:50:49.000z"' } now wish find out how many of these objects has value is_seen set 1 , conversation_id set 38.
i solve using foreach loop, looking solution cleaner , maybe more efficient.
my application angularjs application, i'm looking either native javascript or angular ways solve this.
you can use native array.filter() function:
var countofseenitems = my_array.filter(function (el) { return el.conversation_id == 38 && is_seen == 1; }).length;
Comments
Post a Comment