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

194
Vistas
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 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