I've been working on developing this web application in VUE.js, but I'm facing an issue with a specific function where I am attempting to sum the values of each object within an array. This is resulting in a NaN (Not a Number) error. Let's take a look at the code below:
SCRIPT
data(){
return{
array:[
{ product_name: "Chain Saw",
product_free: 2,
product_free_discount: 306.8,
product_id: 1,
},
{ product_name: "Ox",
product_free: 1,
product_free_discount: 60.8,
product_id: 1,
}
],
totalDiscEquals:0,
}
}
In my computed property, I have defined the following function:
COMPUTED
totalDiscObUnique() {
let total = this.array.reduce(
(a, b) => a + b.product_free_discount,
0
);
console.log(total);
return this.totalDiscEquals=total;
},
For the creation process, I used the created module as shown below:
created(){
this.totalDiscObUnique;
However, when checking the value of totalDisEquals using console log, it shows NaN. Any insights on why this might be happening or suggestions for resolving the issue would be greatly appreciated.