JSFiddle - React, Tailwind, and code Playground
JavaScript
function Person(name, status) {
this.name = name;
this.status = status;
}
// change `status` array reference, e.g., to `arr`
var arr = {
status: []
};
var array = ["bill", "bob", "carl", "ton"];
$(arr).queue("status", $.map(array, function(curr) {
return function(next) {
var name = curr;
// do asynchronous stuff
$.ajax({
url: "/echo/json/",
data: {
json: JSON.stringify({
stream: null
})
}
})
.then(function(data) {
if (data.stream == null) {
var person = new Person(name, "dead");
console.log(name, person);
arr.status.push(person);
}
})
.then(next) // call nest function in `"status"` queue
}
}))
.dequeue("status")
.promise("status")
.then(function() {
// `this` : `arr` as jQuery object
// `this[0].status`: array containing objects pushed to `arr.status`
console.log(this[0].status)
});