I currently working with fetch
api in javascript and i have an array of months what i wanted is that to get the value of month from the database and the value is correct, but then the result in console
was re arraging the array of months, how can I prevent this from re-arraging the arrays?
async function getMonthAccomplishment(m, s) {
this.m = m;
this.s = s;
const param_point = 'filecase/monthaccomplishment/' + this.m + '/' + this.s;
this.endpoint = url() + param_point;
return await fetch(this.endpoint, {credentials: 'include'})
.then((resolve) => {
if(resolve.ok) {
return resolve.text();
}
}, rejected => { console.error(rejected); })
.then((response) => {
return response;
}).catch((error) => {
console.error(error);
});
}
let PostMonthAccomplishment = function() {
this.m = '';
this.s = '';
this.t = '';
};
PostMonthAccomplishment.prototype.set = function(m, s, t) {
this.m = m;
this.s = s;
this.t = t;
if(typeof this.m === 'object' && typeof this.s === 'string') {
this.m.forEach((month) => {
getMonthAccomplishment(month, this.s)
.then((data) => {
console.log(month + ': ' + this.s + ' -> ' + data);
});
});
} else {
console.error('invalid typeof!');
}
};
const months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
const status = ['beginning+balance', 'case+receive', 'Decided/Report+&+Recom.+Submitted+from+Pending'];
let pma = new PostMonthAccomplishment();
pma.set(months, status[1], '');
then the result: sometimes
dar:27 january: case+receive -> 0
dar:27 april: case+receive -> 0
dar:27 may: case+receive -> 0
dar:27 march: case+receive -> 0
dar:27 june: case+receive -> 0
dar:27 february: case+receive -> 0
dar:27 july: case+receive -> 0
dar:27 august: case+receive -> 0
dar:27 september: case+receive -> 0
dar:27 october: case+receive -> 0
dar:27 november: case+receive -> 0
dar:27 december: case+receive -> 0
sometimes
dar:27 january: case+receive -> 0
dar:27 february: case+receive -> 0
dar:27 june: case+receive -> 0
dar:27 april: case+receive -> 0
dar:27 march: case+receive -> 0
dar:27 may: case+receive -> 0
dar:27 july: case+receive -> 0
dar:27 august: case+receive -> 0
dar:27 september: case+receive -> 0
dar:27 october: case+receive -> 0
dar:27 november: case+receive -> 0
dar:27 december: case+receive -> 0