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"];
$.when.apply($, $.map(array, function(curr) {
var name = curr;
return $.ajax({
url: "/echo/json/",
dataType: "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(function() {
// `this` : `arr` as jQuery object
// `this[0].status`: array containing objects pushed to `arr.status`
console.log(arr.status)
});