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

176
Vistas
How to check for duplicates in a list and save each email one by line in a file

I have a list like this:

[
  'test@t-online.de',
  'kontakt@test.de',
  'info@test.de',
  'test@gmx.de',
  'kontakt@test.de',
]

I want to check for duplicates and save the list in a txt file with one email in each line. The final result would be in this case:

      test@t-online.de
      kontakt@test.de
      info@test.de
      test@gmx.de
 

fs.writeFileSync('./results/test.txt', list)

How to do that?

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

0

You can perform that by performing a loop through the Array if emails and perform a filter to like bellow

let emails = [
  'test@t-online.de',
  'kontakt@test.de',
  'info@test.de',
  'test@gmx.de',
  'kontakt@test.de',
];

let result = emails.reduce((accumulator, current) => {
  if(accumulator.indexOf(current) ===  -1){
    accumulator = accumulator.concat(current);
  }
  return accumulator;
}, []);

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Replace list with [...(new Set(list))].join('\n')

  • new Set() ensures only duplicates are removed and only unique elements remain.
  • join('\n') transforms the Array into a string separated by new-line (\n) character.

const list = [
  'test@t-online.de',
  'kontakt@test.de',
  'info@test.de',
  'test@gmx.de',
  'kontakt@test.de',
];
console.log([...(new Set(list))].join('\n'));

about 4 years ago · Juan Pablo Isaza Denunciar

0

for removing duplicated emails:

arr = [...new Set(arr)];

for writing

var writeStream = fs.createWriteStream('./results/test.txt');
writeStream.on('error', function(e) { 
  /* handel error here */ 
});
arr.forEach(email => writeStream.write(email + '\n'));
writeStream.end();

To append data to an existed file Create write stream in append mode

var writeStream = fs.createWriteStream('./results/test.txt', { 'flags': 'a', 'encoding': null, 'mode': 0666});

refer here

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