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

265
Vistas
How to remove duplicate elements from an array of objects JS

I have array objects with keys path and current. How to remove duplicate elements, where key current has the same value.

let arrPath = [{
  path: [1, 2],
  current: "K"
}, {
  path: [0, 3],
  current: "I"
}, {
  path: [1, 3],
  current: "N"
}, {
  path: [1, 4],
  current: "N"
}, {
  path: [0, 2],
  current: "G"
}, {
  path: [2, 2],
  current: "G"
} ];

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can remove duplicate objects (duplicate object in the sense that it contains duplicate current property) by using reduce.

let arrPath = [{ path: [1, 2], current: "K" }, { path: [0, 3], current: "I" }, { path: [1, 3], current: "N" }, { path: [1, 4], current: "N" }, { path: [0, 2], current: "G" }, { path: [2, 2], current: "G" }]

let resultData = arrPath.reduce((elements, obj, index) => {
  let existingData = elements.find(element =>
    element.current === obj.current
  );
  if (!existingData) {
    elements.push(obj);
  }
  return elements;
}, []);

console.log(resultData)

about 4 years ago · Santiago Trujillo Denunciar

0

You can map each value in the array to an entry using the current values for the keys.

Then use these entries to construct a Map object, effectively eliminating duplicate entries.

You can convert the Map back to an array using Array.from

Array.from(new Map(arrPath.map(o => [o.current, o])).values())
about 4 years ago · Santiago Trujillo 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