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

196
Visualizações
Which is the way to check an argument is an array and if not turn it into it in Javascript?

There is a function that receives one argument from a query. If the query is only one item the input will be a string like for example "1". Otherwise if the query has two the argument will be an array like ["1", "2"].

I eventually need to work with an array to use it on a for each and work with the data. So i found this solution but i don't think is the best way to perform this.

//orderInput can be an string "1" or an array of strings ["1","2"]
const parseOrder = (orderInput) => {

    const array = [].concat(orderInput);
    array.forEach(odr => {
        // Here it does something
    });


    return order;
}

about 4 years ago · Juan Pablo Isaza
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