How to make a dazzling call with the native Javascript promise?
I mean, I would like the sentence below to be executed one after the other and that I could know when this sequence of promises are finalized.
var promise;
console.log('iniciando...');
[1, 2, 3, 4, 5].forEach(function (i) {
promise = new Promise(function (resolve) {
setTimeout(function () {
resolve(i);
}, 1000)
});
promise.then(function (value) {
console.log(value);
});
});
console.log('finalizado');