0

arrStoreChildData is an array when I push data. it will show an empty array. I didn't understand what's wrong here.

SECOND query based on the first query result.

let categoryget = (req,res)=>{
    //get live category Data
    let arrStoreParentData = new Array(); //store parent id  
    let arrStoreChildData = new Array(); // arr-store all category 
    connection.query(` SOME SQL QUERY { FIRST QUERY } ='none'`,
    (err_parent,rst_parent)=>{
            if(err_parent){
                console.log(err_parent);
                return res.send({msg:err_parent});
            }else{
                //loop for getting the data  
                //for parent  
                for(var x=0; x < rst_parent.length ; x++){
                    let parent_name = rst_parent[x].category_slug;
                    arrStoreParentData.push(parent_name); 
                    loopchild(parent_name);
                }  
                function loopchild(zz){ 
                    connection.query(` SOME SQL QUERY { SECOND QUERY }=? `,
                    [zz],(err_child,rst_child)=>{
                        if(err_child){
                            console.log(err_child);
                            return res.send({msg:err_child});
                        }else{ 
                            let child_data = rst_child;  
                            arrStoreChildData.push(child_data);   
                        } 
                    }); 
                } 
                
                 return res.send({arrStoreChildData});
            }
    });   
}
  • 1
    Does this answer your question? [How to return the response from an asynchronous call](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Robert Kawecki Nov 12 '21 at 19:26
  • yes. but still don't understand what's wrong. I think I have done something wrong while getting data from the database. May Be the problem in object and array types – manas singh Nov 12 '21 at 19:40

0 Answers0