PASSWORD RESET

Your destination for complete Tech news

Vue

How to get an array or object length in Vue JS?

1.1K 0
< 1 min read

You can get the length of an array in Vue.js using the length property of the array. Here is an example:

<template>
  <div>
    <p>The array has {{ myArray.length }} items.</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      myArray: ['apple', 'banana', 'orange']
    }
  }
}
</script>

In this example, we have an array called myArray with three items. We can get the length of the array by accessing its length property in the component’s template. We use the mustache syntax {{ }} to output the value of myArray.length. When this component is rendered, it will display the following text:

The array has 3 items.

If the length of the myArray array changes, the template will automatically update to reflect the new length.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.