When a javascript Promise object has been fulfilled the function within the then method of that Promise object will get invoked. The below example uses a promise object chain to make the array of elements multiply by themselves and only return those elements that are greater or equal to 16.
let p = new Promise((resolve, reject) => { try { let data = [2, 4, 5, 6, 8, 10]; let data_revise = data.map(x => x * x); resolve(data_revise); } catch(err) { reject("error happened " + err); } }) p.then((data) => { return data.filter(x=> x >= 16); }).then((data) => { for(let i = 0; i < data.length; i++) console.log(data[i]); }).catch(function(error){ console.log(error); });
As you might have guessed the outcomes are as follows:-
16 25 36 64 100
4 has not been included in the above printout because it is lesser than 16.