Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda