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

189
Vistas
JS find array of String and Array Object without duplicates

I had a lists of duplicate array of String and array of object. I want to find the property into one particular object of array uniquely without duplication of array object. If can done in lodash library, it would be awesome.

const arr1 = ['test@email', 'test2@email']
const arr2 = [{ id: 1, email: 'test@email' }]

Expected result

['test2@email']

this is what I done so far By turning arr1 into object frist so I can compare with arr2

 const emailLists = _.map(arr, function (item) {
    console.log(item)
    return { email: item }
  })

then merge them to together and used uniq to remove duplicates

 const merge = _.unionBy(array1, array2, 'email')
 const result _.uniq(merge, 'email');

I think it still not a good process and not clean

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

0

You can do it without lodash

const arr1 = ['test@email', 'test2@email']
const arr2 = [{ id: 1, email: 'test@email' }]


const emailToDelete = arr2.map(a => a.email)

const result = arr1.filter(e => !emailToDelete.includes(e))

console.log(result)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use lodash chain to solve that:

const result = _([...arr1, ...arr2.map(i => i.email)]) // ['test@email', 'test2@email', 'test@email']
    .countBy() // { test@email: 2, test2@email: 1 }
    .pickBy(count => count === 1) // { test2@email: 1 }
    .keys() // ['test2@email']
    .value();
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use filter on the first array and check that an email address matches with some of your objects in the second array. So even if it matches with multiple objects, the matching email will only be in the output once.

I want to find the property into one particular object of array uniquely without duplication of array object

So then your expected output is wrong, as you provide an email that is not found in the object array. I guess that was a typo in your question.

const arr1 = ['test@email', 'test2@email']
const arr2 = [{ id: 1, email: 'test@email' }]

const result = arr1.filter(search => arr2.some(({email}) => email == search));

console.log(result);

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