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
Construct a new array based on filter results of an API

I have an API that returns a list of brands which is an array of objects. I tried to filter out and kept only specific ones. I can see that it ran twice on the console, but when I tried to push those found brands to the brandNames array, I can't.

let brandNames = []
for (let j = 0; j < brands.length; j++) {

    let code = brands[j]

    let brands = {
        api: 'brands',
        filters: [`code:${code}`],
    }

    axios.post(window.URL, brands).then((response) => {
 
        let brand = response.data.groups.filter((item) => {
            return item.brands[0].code == code
        })

        console.log('brand', brand) //ran 2 times 

        if (brand) {
            brandNames.push(brand[0].brands[0].name) // push into array 
        }
    })
}

console.log(brandNames) // got [] empty 

enter image description here

I have a feeling that things went out of context somewhere, but I have no idea where it is ....

about 4 years ago · Santiago Trujillo
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