Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
Remove Duplicates from Array of Objects (Node.js)

without _.uniq, as it doesn't work on my platform (autocode)

I tried filtering using ==, but it didn't work. I also tried _.uniq, which didn't work either.

Code:

      var tags = [...new Set(bot.tags)]

      for (var i = 0; i < bot.tags.length; i++) {
        tags1 += `\`${tags[i].label}\` `;
        
        tags2.push({
          label: `${tags[i].label}`,
          value: `${tags[i].name}`,
          default: false,
        });
      }
      
      console.log(tags2);

Current value of tags2:

[
  { label: 'Anime', value: 'anime', default: false },
  { label: 'Social', value: 'social', default: false },
  { label: 'Moderation', value: 'moderation', default: false },
  { label: 'Fun', value: 'fun', default: false },
  { label: 'Anti-scam', value: 'anti-scam', default: false },
  { label: 'anti-scam', value: 'anti-scam', default: false },
  {
    label: 'Multiple Languages',
    value: 'multiple-languages',
    default: false
  },
  { label: 'Minecraft', value: 'minecraft', default: false },
  { label: 'Fun', value: 'fun', default: false },
  { label: 'Moderation', value: 'moderation', default: false },
  { label: 'Logging', value: 'logging', default: false },
  { label: 'anti-nuke', value: 'anti-nuke', default: false },
  { label: 'Utility', value: 'utility', default: false },
  { label: 'Multi-language', value: '-multi-language', default: false },
  { label: 'Anime', value: 'anime', default: false },
  { label: 'Logging', value: 'logging', default: false },
  { label: 'Together', value: 'together', default: false },
  { label: 'Utility', value: 'utility', default: false },
  { label: 'anti raid', value: 'anti-raid', default: false },
  {
    label: 'DiscordTogether',
    value: 'discordtogether',
    default: false
  },
  { label: 'Social', value: 'social', default: false }
]

It seems that there are a few values with double value, although they have a different label. How can I fix that?

(I need to sort not by uniqueness of the whole object - only by it's value)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

if you are using javaScript you can use Set

A set is a collection of items which are unique i.e no element can be repeated. Set in ES6 are ordered: elements of the set can be iterated in the insertion order. Set can store any types of values whether primitive or objects.


// Use to remove duplicate elements from the array 

const numbers = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5]

//spreading numbers of the object into an array using the new operator
console.log([...new Set(numbers)]) 

// [2, 3, 4, 5, 6, 7, 32]

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!