[Vuejs]-How to count array length skip empty

1๐Ÿ‘

โœ…

Try to filter the numbers before return

computed: {
  total() {
    return this.numbers.filter(({number}) => Boolean(number)).length;
  },
},

0๐Ÿ‘

you can use array filter to make new array with custom condition

computed: {
total() {
  return this.numbers.filter(el => el.number != null).length;
},

},

Leave a comment