Objective: I want to count the occurrences of an id matching between arrays The code below finds the match but we need to count the result
var arr1 = [
{
"image" : "FF815_1.jpg",
"id" : "NO"
}, {
"image" : "FF815_0.jpg",
"id" : "NO"
}, {
"image" : "FF815_4.jpg",
"id" : "NO"
}, {
"image" : "PIOJD_2.jpg",
"id" : "NO"
}, {
"image" : "PIOJD_4.jpg",
"id": "JD"
} ];
var arr2 = [
{
"image" : "FF815_1.jpg",
"id" : "NO"
}, {
"image" : "FF815_0.jpg",
"id" : "NO"
}, {
"image" : "FF815_4.jpg",
"id" : "NO"
}, {
"image" : "PIOJD_2.jpg",
"id" : "JD"
}, {
"image" : "PIOJD_4.jpg",
"id" : "JD"
} ];
angular.forEach(arr1, function(value1, key1) {
angular.forEach(arr2, function(value2, key2) {
if (value1.id === value2.id) {
console.log(value2.id);
}
});
});
Heres a fiddle: https://jsfiddle.net/62s0ae7v/