Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda