HDTuto.com

Get Array Length in Vue JS | Get Object Length in Vue JS



Two days ago my developer was working with array in vue js and he need to get length of array. he was new with javascript then he told me for help. i create simple example of get array length in vue js and get object length in vue js, so understood very well that thing.

I give you bellow very simple example so you can understand how to getting array length or object length in vue js code.

My Example:

<!DOCTYPE html>

<html>

<head>

<title>Vue JS Get Array Length Or Object Length Example - ItSolutionStuff.com</title>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

</head>

<body>

<div id="app">

<ul id="exampleApp">

<li v-if="myArray.length">Object Length = {{ myArray.length }}</li>

<li v-for="value in myArray">

{{ value.category }}

</li>

</ul>

</div>

<script type="text/javascript">

var app = new Vue({

el: '#app',

data: {

myArray: [

{ category: 'Laravel' },

{ category: 'PHP' },

{ category: 'Codeigniter' }

]

}

})

</script>

</body>

</html>

Output:

Object Length = 3

Laravel

PHP

Codeigniter

I hope it can help you...




August 15, 2019 | Category : Vue.js
Related Posts



Blog Search