How to parse all line items of a quote programatically

Hello. I have a custom discounts module that applies to the line items of a quote. To achieve this I have a button in the line item row that says "Apply pricing". All good so far. Now I want to make a button in the HEADER of the line items table that will be "Apply pricing to ALL". When I click this future button I want to go through all the line items present and call the logic of the earlier mentioned "Apply pricing" button. How do I do this from Javascript code? VERY IMPORTANT!!! This button must also function for unsaved, not yet existing, new line items (like you create a quote and before you pressed save). So query-ing it in the database won't work directly.