How I can match every articles object which are containing the matching values from the "tags" array, for example if I want to only list the articles which containing "foo" and "bar" keywords?
[
{
"articles": [
{
"_id": "0",
"body": "This is a test article 1.",
"tags": [ "foo", "bar" ]
},
{
"_id": "2",
"body": "This is a test article 2.",
"tags": [ "baz", "bam" ]
},
{
"_id": "4",
"body": "This is a test article 4.",
"tags": [ "foo", "bar", "baz", "bam" ]
}
]
}
]
Here is the router in my Express app which is calling this JSON file:
router.get('/:tag', function (req, res, next) {
fsAsync(function(err, data) {
var articles = data[0].articles.reverse();
var q = articles.filter(function (article) {
return article.tags === req.params.tag;
});
var json = [{ articles: q }];
// I want the results here
console.log(json);
res.render('blog-tag', {
layout: 'main',
data: json
});
});
});