javascript – how to make sure that i expect to solve and start another

Hello, I'm new and I'm only turning on the JS that currently uses views. but I still can not turn the normal process into asynchronous waiting, nor promise, to the old.

I know that I have to enter that directly into the problem.

I have a method in sight.

Download (date) {

leave posicaoscroll = window.scrollY
data.map (res => this.messages.unshift (res))
window.scrollTo (0, posicaoscroll)

}

Sometimes when I run it works by placing the data at the beginning of the array to make a message load progressively, scrolling changes position, so I use it so that it continues in the msm box, plus the insertion time does not work. I believe that one is faster than others thanks to the function js.

so how to turn this function into something that only happens after having

data.map (res => this.messages.unshift (res))

perform

window.scrollTo (0, posicaoscroll)

Thank you in advance.