for (var i=0; i<vm.tags.length; i++) {
if (selectedTags[0]) {
if (vm.tags[i].term_id === selectedTags[0].term_id) {
vm.tags[i].border1 = true;
}
}
if (selectedTags[1]) {
if (vm.tags[i].term_id === selectedTags[1].term_id) {
vm.tags[i].border2 = true;
}
}
if (selectedTags[2]) {
if (vm.tags[i].term_id === selectedTags[2].term_id) {
vm.tags[i].border3 = true;
}
}
}
vm.tags
contains a comprehensive list of tags, usually up to 20 or more. selectedTags
, on the other hand, is an Array that can hold a maximum of 3 tags, which may have the same ids as some of the tags in vm.tags
.
In cases where tags from selectedTag
match with tags in vm.tags
, I need to update the border value of those specific vm.tags
.
Is there a more efficient approach to achieve this objective without repeating code like shown above?
Example of the selectedTags
Array:
[object, object, object]
Individual Object structure within the Array:
{
selected: true,
term: "term_name",
term_id: 2349506
}