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

296
Vistas
How to remove duplicate names in an object with multiple arrays?

I have the object below with different arrays and I want to remove the duplicate names that are showing. How can I do that?

How duplicate names look like

The data is being printed this way

All data

The dsUserId is what is being repeated. And I want to be able to remove duplicate dsUserId

Here is where all the data is being generated.

  this.setState({
      user_connections: results.data.data.connections,
      newLeads: results2.data.data,
      promotion: results3.data.data,
      hasPromotion: results3.data.data.length === 0 ? false : true,
      promoPlan: promoPlan,
      toRemoveDays: excludedDays
    });

    console.log("All data", this.state.user_connections)
  }

And here is where the data is being rendered.

  <select
    id="user_select"
    style={{ width: "70%" }}
    name="selectedUser"
    onChange={e => {
      this.setState({
        [e.target.name]: e.target.value.trim()
      });
    }}
    className="form-control"
  >
    <option value={null} disabled hidden selected>
      Please Select
    </option>
    {this.state.user_connections.map(u => (
      <option value={u.parentId} key={u.parentId}>
        {u.displayName}
      </option>
    ))}
  </select>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use filter to achieve this for eg:

const userConnections = (connections) => {
    const uniqueIds = [];
    return connections.filter(connection => {
       if (!uniquesIds.includes(connection.dsUserId) {
           uniqueIds.push(connection.dsUserId);
           return connection;
       }
    })
};

and then :

user_connections: userConnections(results.data.data.connections)
about 4 years ago · Juan Pablo Isaza Denunciar

0

Not sure if the best way, but I would first make a Set of all the unique dsUserIds and then filter the first in the user_connections array for each dsUserId:

let tsUserIds = [];
this.state.user_connections.forEach(user => {
  tsUserIds.push(user.dsUserId);
})
tsUserIds = [...new Set(tsUserIds)]; // filters out the duplicates
let uniqueConnections = [];
tsUserIds.forEach(id => {
  uniqueConnections.push(this.state.user_connections.filter(user => user.dsUserId === id)[0]);
})
console.log(uniqueConnections);
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