Для каждого элемента данных вы проверяете, есть ли идентификатор в массиве идентификаторов, и, если да, что-то делаете
const ids = [
"id1",
"id2",
"id3"
]
const data = [
{
id: "id3", // dynamically populated and can vary, we need this property
prop2: "prop2", // not needed
prop3: "prop3" // not needed
}
]
// if we have the id in ids array, do something
if (data.some(d => ids.indexOf(d.id) > -1)) {
// do something
}
Используя lodash:
const ids = [
"id1",
"id2",
"id3"
]
const data = [
{
id: "id3", // dynamically populated and can vary, we need this property
prop2: "prop2", // not needed
prop3: "prop3" // not needed
}
]
// if we have the id in ids array, do something
if (_.some(data, d => ids.indexOf(d.id) > -1)) {
// do something
}