[Vuejs]-Vuejs search in array of object

0๐Ÿ‘

I think this should work:

let posts = this.posts;
if (typeof this.checkedTags !== 'undefined' && this.checkedTags.length > 0) {
  posts = posts.filter(post => {
    return post.tags.some(tag => checkedTags.includes(tag.name))
  })
}

Basically it will just filter all the posts where at least one tag is in the checkedTags array. Depending on your needs you can also check if all the tags of the post are there with post.tags.every()

Leave a comment