Untitled

 avatar
unknown
plain_text
5 months ago
589 B
2
Indexable
function getUniqueElements() {
  const arr = [
    {
      id: 36,
      business_name: 'Hydro Plumbing Solutions'
    },
    {
      id: 107,
      business_name: 'Hydro Plumbing Solutions (NSW)'
    },
    {
      id: 108,
      business_name: 'Hydro Plumbing Solutions (NSW)'
    },
    {
      id: 109,
      business_name: 'Hydro Plumbing Solutions (NSW)'
    }
  ];

  const seen = new Set();
  return arr.filter(item => {
    const key = item.business_name;
    const isDuplicate = seen.has(key);
    seen.add(key);
    return !isDuplicate;
  });
}

console.log(getUniqueElements())
Editor is loading...
Leave a Comment