Gets an array values consistently, read them and resolve with results (this is a basic example that was done to understand how I can read array, make an ajax call with value and resolve for getting next one). The values are printing in arow.
'use strict';
//The sandbox http://jsbin.com/leraku/edit?js,console
let mas = [1, 2, 3];
let prom = function (value) {
return new Promise(resolve => {
setTimeout(() => {
console.log(value);
resolve();
}, 400);
});
}
let seq = function (arr) {
let ind = 0;
function next () {
if (ind < arr.length) {
prom(arr[ind++])
.then(next);
}
}
next();
}
seq(mas);