This is what i tried - didnt work for me , and how i solve this using async-await ?
var array = [4, 2, 7, 1];
var prom = new Promise(function(myRsolve, myReject) {
var sum = array.reduce((x, y) => x + y);
setTimeout(function() {
myResolve(sum);
}, 3000);
prom.then(function(value) {
document.getElementById("tot").innerHTML = value;
})
});
<p>Array total 4+2+7+1: </p>
<h2 id="tot"></h2>