I have an array that I find in the searchName section, and in the resultName section I separate the duplicate names, and in the filters section I want to display the objects that have those duplicate names in the console.log, but an empty array
Please help me to get the answer
const data = [
{id: 1,name: "Liam",age: 20},
{id: 1,name: "Noah",age: 22},
{id: 1,name: "Liam",age: 20},
{id: 1,name: "Elijah",age: 18},
{id: 1,name: "Elijah",age: 18}
]
const searchName = data.map(item => item.name)
console.log(searchName);
const toFindDuplicates = arry => arry.filter((item, index) => arry.indexOf(item) !== index);
const resultName = toFindDuplicates(searchName)
console.log(resultName);
const filters = data.filter(x => x.Name === resultName)
console.log(filters);