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

193
Views
Getting duplicate results from DB
let absent_remove = result_database.filter(item => item.absentday != absent_days)
console.log("absent_remove", absent_remove);

I got this piece of code, I have multiple values in the database, I also joined the absent table with another table. This execution works properly, its meant to catch people who are absent on current day (today is friday = 5, so people absent on friday are removed from the array).

However, the remaining results are duplicated. As you can see the values are mostly all the same, but the absentday is causing for duplicates. I need it so that it only takes 1 one of the individual IDs

absent_remove [
  {
    id: 49,
    absent_id: 1,
    absentday: 3,
    name: 'testing',
    selected: 1,
    slack_id: 'test',
    absent: 0
  },
  {
    id: 49,
    absent_id: 1,
    absentday: 2,
    name: 'testing',
    selected: 1,
    slack_id: 'test',
    absent: 0
  },
  {
    id: 50,
    absent_id: 2,
    absentday: 1,
    name: 'hello1',
    selected: 0,
    slack_id: 'hello1',
    absent: 0
  },
  {
    id: 50,
    absent_id: 2,
    absentday: 4,
    name: 'hello1',
    selected: 0,
    slack_id: 'hello1',
    absent: 0
  }
]

It should become this

{
        id: 49,
        absent_id: 1,
        absentday: 2,
        name: 'testing',
        selected: 1,
        slack_id: 'test',
        absent: 0
      },
      {
        id: 50,
        absent_id: 2,
        absentday: 1,
        name: 'hello1',
        selected: 0,
        slack_id: 'hello1',
        absent: 0
      },

SQL QUERY

db.connect(function (err) {
    db.query("SELECT id, developers.absent_id, absentday, name, selected, slack_id, absent FROM developers, absent WHERE absent.absent_id=developers.absent_id",
        (err, result, fields) => {
            if (err) {
                console.log(err);
            } else {
                result_database = Object.values(JSON.parse(JSON.stringify(result)));
                console.log("Result from all Database Rows", result_database);
                resultStatement();
            }
        })
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const arrUniq = [...new Map(arr.map(v => [v.id, v])).values()]

Helped me out thanks to jsN00b redirection thread. This catches out the duplicate IDs.

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!