Is it possible to return matching values by comparing JSON arrays. For example;
0 : ['cat1', 'cat2']
1 : ['cat2', 'cat3']
2 : ['cat2', 'cat4']
The above should return 'cat2'
as that exists in all 3 arrays.
EDIT: I found this snippet (Finding matches between multiple JavaScript Arrays) which appears to do the first part;
var result = obj.shift().filter(function(v) {
return obj.every(function(a) {
return a.indexOf(v) !== -1;
});
});
console.log(result);
However, if an array is added that has no matches, this should return false
and no results;
0 : ['cat1', 'cat2']
1 : ['cat2', 'cat3']
2 : ['cat2', 'cat4']
3 : ['cat5']
Is this possible?
2
Answers
Is actually the answer in this case.
you can easily do that using python code, here’s an example: