Loop nested database queries and want to add attributes to the checked data.

[{ID: 1, name: "Home", parent_ID:"0"},
{ID: 2, name: "Wisdom", parent_ID:"0"},
]
db.query ( SELECT * FROM column_table WHERE parent_ID=0 , (err,data) = > {

    if(err){
        console.log("err1:   "+err)
        res.status(500).send("database err").end();
    }else{
        data = JSON.parse(JSON.stringify(data))
        for(var i=0;i<data.length;iPP){
            db.query(`SELECT * FROM column_table WHERE parent_ID=2`,(err,child_data)=>{
                if(err){
                    console.log("err2:   "+err);
                    res.status(500).send("database err").end();
                }else if(child_data.length==0){
                    data[i].child_column=[];
                }else{
                    data[i].child_column=child_data;
                }
            })
        }
     res.render("admin/index.html",{column_data:data})
    }                
  })

this is the result of the console.log (data) output after my query. I want to add an attribute to each object in the array. Direct data [I] .child _ column="222", is wrong. How should I add it

Mar.03,2021

first give the operation result of the data data = JSON.parse (JSON.stringify (data)) , and then try the operation


use Array.apply () to have an array of classes call an array's methods, and then you can use the map method to add attributes to each item.

  https://github.com/bsspirit/a.

Menu