[Vuejs]-VueJs logical conditons with array elements

0👍

To get all array items that have a falsy B1 value, use Array.prototype.filter:

const falsyB1Items = this.Array1.filter(item => !item.B1)

Then you could reduce those items:

return falsyB1Items.reduce((sum, numbers) => sum += numbers.Numbers, 0)

demo

0👍

You can do it just by one function like this:

computed: {
    sumOfNumbers() {
        this.Array1.map(obj => {
            if (obj.B1 === false) {
                this.sum += obj.Numbers; // The sum is stored in the 'sum' var
            }
        });
        return this.sum;
    }
}

Does it works the way you want?

Leave a comment