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

178
Vistas
Remove nested array from array of arrays

First of all I'm not entirely sure if this is the right approach for the problem I am having but here it goes.

I have two arrays

const projects = ["PP", "JJ"]
const issues = ["10000", "10002", "100003"]

For each issue I want to create an object like so:

{
  "issueTypeId": "10002",
  "projectId": "PP",
  "viewType": "GIC"
}

And at the end finish with an array of objects, something like:

[{
   "issueTypeId": "10002",
   "projectId": "PP",
   "viewType": "GIC"
},
{
   "issueTypeId": "10000",
   "projectId": "PP",
   "viewType": "GIC"
}]

So far this is my logic

const projects = ["PP", "JJ"]
const issues = ["10000", "10002", "100003"]

const p = issues.map(issue => {
    return projects.map(project => {
        return {issueTypeId: issue, projectId: project, viewType: "GIC"}
    })
})

console.log(p)

But as you can see I get an array of arrays at the end which I'm pretty sure is due to the double .map logic.

1st - Is there a better way to achieve my objective?

2nd - If not, how to remove the inner array and get a single one

Thank you

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

0

Use flatMap instead of map. Plus, by choosing your variables wisely and using abbreviated form of arrow functions you could use the following:

const projects = ["PP", "JJ"],
      issues = ["10000", "10002", "100003"],
      viewType = "GIC",

      p = issues.flatMap(issueTypeId =>
          projects.map(projectId => ({issueTypeId, projectId, viewType}))
      );

console.log(p)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try this

const projects = ['PP', 'JJ'];
const issues = ['10000', '10002', '100003'];

let outArray = [];
issues.forEach((i) => {
  projects.forEach((p) => {
    outArray.push({
      issueTypeId: i,
      projectId: p,
      viewType: 'GIC',
    });
  });
});

console.log(outArray);
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