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

179
Visualizações
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 à 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