filter duplicates

PHOTO EMBED

Fri Jul 19 2024 06:03:42 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #function #filter

function generateButtons(buttons) {
    // get the dataset value
    let uniqueCategories = [...new Set()];

    buttons.forEach((button) => {
      const category = button.dataset.category;
      uniqueCategories.push(category);
    });

    uniqueCategories = uniqueCategories.filter(function (item, pos) {
      return uniqueCategories.indexOf(item) == pos;
    });

    uniqueCategories.unshift("All");

    console.log(uniqueCategories);

    // return ` <button type="button" class="filter-btn" data-id="${category}">${category}</button>`;
  }
content_copyCOPY