Vue.js Count Array Items


We can use native JavaScript length property to Vue.js Count Array Items. Here in this tutorial, we are going to explain how you can use this property to count Array items in vue.js. You can also use our online editor to edit and run the code online.


Vue.js Count Array Items Example

Here is an example of length property in vue.js-

Example:

<div id="app">
	<p>item 1 = {{ item1 }}</p>
	<p>Length = {{result}}</p>

	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  item1:['12', '10', '9','5', '6', '4'],
	  result:''
  },
  
   methods:{
    myFunction: function () {		
		this.result = this.item1.length;
		
    }
	}

});
</script>

Try it »

Output of above example-

Vue.js Count Array Items

Advertisements

Add Comment

📖 Read More