Javascript find pro rate value on the every month end in between two dates

I need to calculate pro rated value of every month end between two dates value. My sample values are here below.

enter image description here

I can able to arrive the solution using the for loop and the formula given below.

For every month,

(Number of month end days / Total number of days ) * Final value

I wanted to get pro rate value of End of January, February, March, April, May of Item ‘A’. But Is there any Javascript way to arrive this solution with the efficient code?