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

142
Vistas
How to find a duplicate value in this object array?
    zones = [
      {zone:'A' : price:'20'},
      {zone:'B' : price:'20'},
      {zone:'C' : price:'20'},
      {zone:'A' : price:'20'},
    ];

this is my array of objects how do I find the duplicate value if zone 'A' is Repeated twice I need to Find That?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

zones = [{
    zone: 'A',
    price: '20'
  },
  {
    zone: 'B',
    price: '20'
  },
  {
    zone: 'C',
    price: '20'
  }
];

var result = []

for (let i = 0; i < zones.length; i++) {
  for (let k = 1; k < zones.length; k++) {
    if (zones[i].zone === zones[k].zone && i != k && result.indexOf(zones[i].zone) == -1) {
      result.push(zones[i].zone)
      console.log(zones[i].zone)
    }
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

found this answer here : post 1

 var zones = [
    {zone:'A' : price:'20'},
    {zone:'B' : price:'20'},
    {zone:'C' : price:'20'},
    {zone:'A' : price:'20'},
 ];

 unique = [...new Set(zones.map(propYoureChecking => 
    propYoureChecking.zone))];
    if (unique.length === 1) {
    console.log(unique);
 }

and for normal arrays : post 2

You can do it a few different ways: here's one (from the post):

 const arry = [1, 2, 1, 3, 4, 3, 5];

 const toFindDuplicates = arry => arry.filter((item, index) => arr.indexOf(item) !== index)
 const duplicateElementa = tofindDuplicates(arry);
 onsole.log(duplicateElements);

// Output: [1, 3]
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your requirement is a bit vague but assuming you want to find the index of the duplicate object(s).


zones = [
{zone:'A', price:'20'},
{zone:'B', price:'20'},
{zone:'C', price:'20'},
{zone:'A', price:'20'},
];

const zoneAIndices = [];

zones.forEach((zone, index) => {
 if( zone.zone === 'A') {
   zoneAIndices.push(index);
 }
});

Now zoneAIndices[1] has the index of the duplicate item.

Note:

the zones array you have defined is incorrect, instead of : between zone and price it should be a ,

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