Skip to content
Advertisement

Apply discount on array of object in loop whichever object paid value is higher?

I have array of object which have key paid. I want to apply discount on all objects expect object which paid value is higher using loop.

JavaScript

On above array of object name booking i want to make loop and apply discount by adding key discount:true in that object except higher paid value object.

This is what i want after loop

JavaScript

Advertisement

Answer

You could get max paid value first and then apply the new property, if necessary.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement