[Vuejs]-I need to remove duplicated comments from every post

0👍

If reassigning comments is okay, this should do the trick:

let unique = [...new Set(state.posts)];

unique.forEach((post) => {
  const seenIds = new Set();
  post.comments = post.comments.filter((c) => {
    if (seenIds.has(c._id)) {
      return false; // Already saw it
    }
    seenIds.add(c._id);
    return true;
  });
});

Leave a comment