I have an Object called data contains list of arrays. I just map my data to get a specific column data as follows.
const DisplayData = data
?.filter((vendors) => vendors?.vendors != null)
.map((risk) => {
return (
<tr>
<td
className="link_hover"
onClick={() => {
dispatch(vendors(risk.vendors));
}}
>
<Link
className=" link_hover text-decoration-none second-color vendor_list_font_size"
to="/vendor_critical_details"
>
{risk.vendors}
</Link>
</td>
</tr>
);
});
From the above code I got list of ``vendor` names. but I got duplicate names. Is there any trick to remove duplicates from the result?
Thanks
Reduce instead of filter
const vendorList = data
?.reduce((acc,vendors) => {
const vendor = vendors?.vendors ?? null
if (vendor != null && !acc.includes(vendor)) acc.push(vendor)
return acc
},[]);
const DisplayData = vendorList.length === 0 ? "" : vendorList.map(risk => ...