Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!