I am trying to replicate a code similar to the current one shown on this page: http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html
The array loop calculates a total price, however, I am attempting to break the loop once a certain criteria is met.
viewModel.total = ko.computed(function() {
    var total = 0;
    ko.utils.arrayForEach(this.items(), function(item) {
        var value = parseFloat(item.priceWithTax());
        if (!isNaN(value)) {
            total += value;
        }
    });
    return total.toFixed(2);
}, viewModel);
What I am trying to achieve, is that if the value is equal to 2 for example, then the loop will stop, and the total.toFixed(2) will equal 0.
I know this is probably a simple one, but I have been looking everywhere for a similar question and have been struggling to find what I am looking for.
I tried creating something very similar to below, but this did not work.
viewModel.total = ko.computed(function() {
    var total = 0;
    ko.utils.arrayForEach(this.items(), function(item) {
        var value = parseFloat(item.priceWithTax());
        if (!isNaN(value)) {
            total += value;
        }
    });
    if (value == 2) {
        return total.toFixed(2) = 0;
}
    return total.toFixed(2);
}, viewModel);
 
    