J
J
jazzus2018-12-26 09:26:36
Vue.js
jazzus, 2018-12-26 09:26:36

How to count objects in a VUE array?

You need to count the number of errors in the errors array, and if there are none, then (long story) ..
I'm trying to count in computed using an example from the Internet

errors_count: function () {
              return this.errors.length
        }

Received validation errors (i.e. the errors array was filled with objects), and
errors_count: undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2018-12-26
@jazzus

The object does not have a length property, so you need to cast it to an array (of values ​​or keys)

errors_count: function () {
    return Object.keys(this.errors).length;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question