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

142
Views
Get undefined or Promise { <pending> } trying to push to an array

I have problems pushing to an array in a SSR page in the below code.

    let categories = []

    categories = await axios.get(`http:/.../${price_list_name}`).then(res => {
        return res.data
    })

    const child_categories = categories.related.category_childs.hits.hits
    const childs_en_names = []
    if (child_categories.length > 0) {
        for (var doc in child_categories) {
            childs_en_names.push(child_categories[doc]._source.en_name)
        }
    }

    const get_products = async (en_name) => {
        await axios.get(`http://.../${en_name}`).then(res => {
            let data = {
                "en_name": en_name,
                "products": res.data.related.childs_products
            }
            return data
        })
    }

    const products = await Promise.all(childs_en_names.map(en_name => get_products(en_name))) 


    // logging
    // console.log(categories.products, 'props')
    console.log(products, 'products')

cosole.log(products, 'products') returns me undefined or Promise { }. I have searched alot but haven't been successfull to make it work.

any help would be highly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're not returning anything from get_products. There's no point in using async/await if you're going to use then too. It sort of defeats the point.

const get_products = async (en_name) => {
  const res = await axios.get(`http://.../${en_name}`);
  const data = {
    en_name: en_name,
    products: res.data.related.childs_products
  }
  return data;
}

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