filter & map

by John Wick

JavaScript

/* var term = [
    "64b64891eec39b2fe53a0ca7"
] */

var term = [
 "64b64891eec39b2fe53a0ca7",
 "64b648c7eec39b2fe53a0ca8"
]


/* var term = [
  "64b648ceeec39b2fe53a0ca9"
] */

/* var term = [
    "0",
    "1"
] */

var checklistTags = [
    "64cd287d49d15a75bd2a1939",
    "64b64891eec39b2fe53a0ca7",
    "64ce8ba775947f51773b7909",
    "64b648ceeec39b2fe53a0ca9",
    "64ce8bae75947f51773b790a",
    "64b648c7eec39b2fe53a0ca8",
    "64b64f3deec39b2fe53a2182"
]

var allTags = [
    {
        "id": "64b64891eec39b2fe53a0ca7",
        "tenantId": "6156b3859471dd19476a28d9",
        "tagName": "AAA",
        "priority": 1,
        "tableData": {
            "id": 0
        }
    },
    {
        "id": "64b648c7eec39b2fe53a0ca8",
        "tenantId": "6156b3859471dd19476a28d9",
        "tagName": "BBB",
        "priority": 2,
        "tableData": {
            "id": 1
        }
    },
    {
        "id": "64b648ceeec39b2fe53a0ca9",
        "tenantId": "6156b3859471dd19476a28d9",
        "tagName": "CCC",
        "priority": 3,
        "tableData": {
            "id": 2
        }
    },
    {
        "id": "64b64f3deec39b2fe53a2182",
        "tenantId": "6156b3859471dd19476a28d9",
        "tagName": "DDD",
        "priority": 4,
        "tableData": {
            "id": 3
        }
    },
    {
        "id": "64cd287d49d15a75bd2a1939",
        "tenantId": "6156b3859471dd19476a28d9",
        "tagName": "1",
        "priority": 5,
        "tableData": {
            "id": 4
        }
    },
    {
        "id": "64cd288a49d15a75bd2a193a",
        "tenantId": "6156b3859471dd19476a28d9",
        "tagName": "2",
        "priority": 6,
        "tableData": {
            "id": 5
        }
    }
]

/* console.log('allTags:', allTags)
console.log('allTags.length:', allTags.length) */

var found = []
for (let i=0; i< allTags.length; i++) {
	if (allTags[i]?.id && term.includes(allTags[i]?.id)) {
  	found.push(allTags[i]?.tableData?.id)
  }
}

const foundIds = allTags
  .filter(tag =>...