How to decrement items in array Incrementally based on the given quantity in Javascript
问题 I have this sample array of objects mangoes:[ { quantity:5}, { quantity:8}, { quantity:13}, { quantity:4} ] When I remove x mangoes, that x should be subtracted from the first element in the array, and if that x exceed the first element then it should reduce the remained quantity in the second item in the array...and so forth. This is to say, I need the quantity to be reduced starting from the first one in the array down to the second if it exceed, to the third etc.. For example, If I buy 2