filter by tags

by John Wick

JavaScript

function filterTags(allTags, tags) {
    return allTags.filter(tag => tags.includes(tag.id));
}

var tags = [
    "a0b9a488-465d-4bb5-b8f5-9300609a52ec",
    "7dea6a59-7c33-46e0-9827-354917038f06"
];

var allTags = [
    {
        "id": "a0b9a488-465d-4bb5-b8f5-9300609a52ec",
        "name": "bini maloi",
        "active": true,
    },
    {
        "id": "7dea6a59-7c33-46e0-9827-354917038f06",
        "name": "bini colet",
        "active": true,
    },
    {
        "id": "91b86d06-d147-43c2-8918-6e3c27bb019e",
        "name": "bini mikha",
        "active": true,
    },
    {
        "id": "51323fd2-e052-4d73-9d48-9d1c71b376a5",
        "name": "bini joana",
        "active": false,
    },
    {
        "id": "44281a80-ebb9-475d-bae6-0cd418d35c7b",
        "name": "bini stacey",
        "active": true,
    }
];

var outputArray = filterTags(allTags, tags);
console.log('outputArray:', outputArray);