В настоящее время я работаю с fetch
API в javascript, и у меня есть массив месяцев, что я хотел, чтобы получить значение месяца из базы данных, и значение является правильным, но затем результат в console
был повторноКак я могу предотвратить повторное размещение массивов в массиве месяцев?
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], '');
тогда результат: иногда
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
иногда
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