используйте filter
и find
в лайках.
const filter = (data, name) =>
data.filter(({ likes }) => likes.find(({ username }) => username === name));
const data = [
{
id: 1,
title: "Lorem",
private: false,
likes: [
{ id: 01, username: "mike" },
{ id: 02, username: "john" },
],
},
{
id: 2,
title: "Ipsum",
private: true,
likes: [
{ id: 03, username: "steve" },
{ id: 04, username: "mike" },
{ id: 05, username: "sara" },
],
},
{
id: 3,
title: "Dolor",
private: false,
likes: [
{ id: 06, username: "brad" },
{ id: 07, username: "cameron" },
{ id: 08, username: "liam" },
],
},
];
console.log(filter(data, "mike"));
console.log(filter(data, "blah"));