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

266
Vistas
Get the index of duplicate values except the first

Below is an example array:

const attD = [1, 2, 3, 4, 3, 3]

How can we get the index of the duplicate values from this array? In this example, 3 is repeated thrice. So, I want to get the index 4, index 5 as these are duplicated at that positions (ignoring the first occurrence).

I have tried the below code, but it is giving me values. Instead, I need the index.

const findDuplicates = attD => attD.filter((item, index) => attD.indexOf(item) !== index);
const duplicates = findDuplicates(attD);
console.log(duplicates);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. With .map(), add the index of duplicated values into the array. For non-duplicate value, will be added with undefined value [Will be filtered in Step 2].
  2. With .filter(), remove the value which is undefined from the array.

const attD = [1, 2, 3, 4, 3, 3];

const findDuplicates = attD => attD.map((item, index) => {
  if (attD.indexOf(item) !== index)
    return index;
}).filter(x => x);  // Equivalent to .filter(x => x != undefined || x != null)

const duplicates = findDuplicates(attD);
console.log(duplicates);

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