2021年4月5日星期一

VueJs logical conditons with array elements

I have an array in my data function, and I want to compute the sum of numbers that have a false record in the array. But I need to do it in the computed section but I'm having trouble with the condition on calculating just the false arrays. How would one set up the logical parameter.

Array1: [                  {Text1: "Some text in an array 1", Numbers: Math.floor(Math.random() * 50), B1: true},                  {Text2: "Some text in an array 2", Numbers: Math.floor(Math.random() * 50), B1: true},                  {Text3: "Some text in an array 3", Numbers: Math.floor(Math.random() * 50), B1: true},                  {Text4: "Some text in an array 4", Numbers: Math.floor(Math.random() * 50), B1: true},                  {Text5: "Some text in an array 5", Numbers: Math.floor(Math.random() * 50), B1: true},                  {Text6: "Some text in an array 6", Numbers: Math.floor(Math.random() * 50), B1: false},                  {Text7: "Some text in an array 7", Numbers: Math.floor(Math.random() * 50), B1: false},                  {Text10: "Some text in an array 8", Numbers: Math.floor(Math.random() * 50), B1: false},                  {Text8: "Some text in an array 9", Numbers: Math.floor(Math.random() * 50), B1: false},                  {Text9: "Some text in an array 10", Numbers: Math.floor(Math.random() * 50), B1: false},              ],              sum: 0  computed:{      sumOfNumbers(){          return this.Array1.reduce((sum, numbers) =>{              return sum += numbers.Numbers;          }, 0)      },      sumOfFalse(){          if(Array1[iii].B1 = 'false'){              return this.Array1.reduce((sum, numbers) =>{                  return sum += numbers.Numbers;              }, 0)          }      },  },  
https://stackoverflow.com/questions/66961738/vuejs-logical-conditons-with-array-elements April 06, 2021 at 09:43AM

没有评论:

发表评论