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

225
Vistas
How to use map function for two arrays and concatenate

I have two arrays.

const test = ["SME","ONE", "TWO"]
const test2 = ["RED"]  // can have multiple elements

I am trying to map over this and return an object like this :

[{SME: "SME", isValid: Y}, {ONE: "ONE", isValid: Y}, {"TWO": isValid: Y}, {"RED": "N"}]

How can I create such Data structure using map ?

I tried :

test.map((item) => ({
   item,
    isValid: Y
})

test1.map((item) => ({
   item,
isValid: N
})

[...test, ...test2]

This way it works , but any other solution for this ? We can not combine these two arrays at start

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

0

Your solution is not bad, you could also use flatMap:

const test = ["SME", "ONE", "TWO"];
const test2 = ["RED"];

const result = [test, test2].flatMap(arr => {
  return arr.map(item => {
    return {
      item,
      isValid: arr === test,
    }
  })
})

console.log(result)

about 4 years ago · Juan Pablo Isaza Denunciar

0

As you suggestet:

[...test, ...test2]

Or using concat

test.concat(test2)

Or without creating a new array, just pushing into test

Array.prototype.push.apply(test, test2)
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