Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
How can i convert multiple arrays to one array in javascript

I have this multiple array and i want to convert it to one array with javascript codes and get data from it with flatMap:

    [
        {
      id: '46892319372',
      user_name: 'testerOne',
      identifier: '20202'
    }
]
[
    {
      id: '15243879678',
      user_name: 'testerTwo',
      identifier: '20201'
    }
]
[
    {
      id: '02857428679',
      user_name: 'testerThree',
      identifier: '20203'
    }
]
[
    {
      id: '65284759703',
      user_name: 'testerFour',
      identifier: '20204'
    }
]

i want to convert this multiple arrays to just one array like this with javascript: I have only one variable that contains this ↓ or maybe more than 4 or less than 4 i don't know i just have a variable that contains the arrays like this in it and i can't put these to another variable or separate them with , or ... i just have this ↓

[
        {
      id: '46892319372',
      user_name: 'testerOne',
      identifier: '20202'
    },
    {
      id: '15243879678',
      user_name: 'testerTwo',
      identifier: '20201'
    },
    {
      id: '02857428679',
      user_name: 'testerThree',
      identifier: '20203'
    },
    {
      id: '65284759703',
      user_name: 'testerFour',
      identifier: '20204'
    }
]

I tried array.concat but i have only one variable with that arrays so i tried list.concat(list) but i got something like this as result :

    [
        {
          id: '46892319372',
          user_name: 'testerOne',
          identifier: '20202'
        },
        {
          id: '46892319372',
          user_name: 'testerOne',
          identifier: '20202'
        }
   ]
   [
        {
          id: '15243879678',
          user_name: 'testerTwo',
          identifier: '20201'
        },
        {
          id: '15243879678',
          user_name: 'testerTwo',
          identifier: '20201'
        }
   ]
   [
        {
          id: '02857428679',
          user_name: 'testerThree',
          identifier: '20203'
        },
        {
          id: '02857428679',
          user_name: 'testerThree',
          identifier: '20203'
        }
   ]
   [
        {
          id: '65284759703',
          user_name: 'testerFour',
          identifier: '20204'
        },
        {
          id: '65284759703',
          user_name: 'testerFour',
          identifier: '20204'
        }
    ]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

What you have here is not a multiple array (an array of arrays), but actually multiple arrays. Not sure how you got here but I am assuming you didn't create these, as the solution would be to just be to wrap these in an array and separate each array with a comma, then anything you do to flatten it will work.

Sorry if this is just too rudimentary an answer for now.

Did you create this (can you easily edit the structure) or were these returned to you?

about 4 years ago · Juan Pablo Isaza Relatório

0

Im not sure if this is what youre after but.. this only works with arrays that contain object literals.

let arrayList = [
  [{
    id: '46892319372',
    user_name: 'testerOne',
    identifier: '20202'
  }],
  [{
      id: '15243879678',
      user_name: 'testerTwo',
      identifier: '20201'
    },
    {
      id: '15243879678',
      user_name: 'testerTwo',
      identifier: '20201'
    }
  ],
  [{
    id: '02857428679',
    user_name: 'testerThree',
    identifier: '20203'
  }],
  [{
    id: '65284759703',
    user_name: 'testerFour',
    identifier: '20204'
  }]
]

function mergeArrays() {
  let arrayObject = []
  for (let arrayLists of arguments) {
    for (let array of arrayLists) {
      if (array.constructor !== Array) continue;
      for (let object of array) {
        if (object.constructor !== Object) continue;
        arrayObject.push(object);
      }
    }
  }

  return arrayObject;
}
console.log(mergeArrays(arrayList))

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda