I am using an ajax to get some of my data from database without refreshing my page. So made this function:
function setElapsedDays(contract){
...
let diff_in_time = end_date.getTime() - start_date.getTime();
let days_elapsed = diff_in_time / (1000 * 3600 * 24);
console.log(this.getVacationEntitlment(contract.id));
let accrued = this.getVacationEntitlment(contract.id) / days_elapsed;
console.log(accrued);
}
async function getTravelEntitlment(contract_id){
let url = window.location;
const response = await fetch(url.origin+"/api/benefits/search/2/"+contract_id);
const object = await response.json();
return object.allotment;
}
but why i am getting NaN
on my accrued
?
Using console.log(this.getVacationEntitlment(contract.id));
I am getting
Promise {<pending>}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: 30
If i console.log()
my object
i get this {id: 2, contract_id: 736, benefit_id: 2, allotment: 30, uom: "Days", …}
How can i get the value of PromiseValue
?