I am returning ASANA's api and trying to push that data into an array. But when I try to console.log array outside the loop it's being empty. I guess I am missing something, but couldn't figure it out.
it's the code block.
let tasks = [];
$.each(projectArray, function(key,project){
    asana.request("GET", "projects/"+project+"/tasks?opt_pretty&opt_expand=(this%7Csubtasks%2B)", function(err, response){
        response.data.forEach((element, key) => {
            if (element.completed === true) {
                let taskObj = {
                    title: element.name,
                    works: "",
                    price1: "",
                    price2: "",
                }
                element.custom_fields.forEach(elem => {
                    if (elem.name === "com_name") {
                        taskObj.works = elem.text_value                                                    
                    } else if (elem.name === "price1") {
                        taskObj.price1 = elem.number_value
                    } else if (elem.name === "price2") {
                        taskObj.price2 = elem.number_value
                    }                        
                })
                tasks.push(taskObj) // data pushed. 
            }
        })
    })
    console.log(tasks) // i can log the data 'till here.
})
var maskedTasks = JSON.parse(JSON.stringify(tasks))
console.log(maskedTasks)
//can't log the data outside of the loop. array is being empty.
I tried to stringify and parse it. But it doesn't work...
