I think I am doing something wrong, I am not able to send value to frontend. res.json(arr) this line of code give [] blank array. but console.log(arr); gives all value what I needed(JSON value).
Code
    var arr = [];
    var messagesPromise = new Promise((resolve, reject) => {
        messages.forEach(function (val,index) {
            arr[val.session] = val;
            if (index === messages.length -1) resolve(arr);
        });
    });
    messagesPromise.then((arr) => {
        console.log("######################");
        console.log(arr);  // this line of code gives json value 
        console.log("######################");
        res.json(arr); // this line of code gives [] array
    });