Vue.JS check if Object or Array is empty


Vue.JS check if Object or Array is empty We can use JavaScript .length property to get the length of object or array in VueJS. Here we are going to create one simple example to demonstrate the use of length property in VueJS.


Vue.JS check if Object or Array is empty Example

You can use the following method to check the whether the array or object is null or not. Here is an example-

Example:

<!DOCTYPE html>
<html>
<head>
 <script src="http://cdn.jsdelivr.net/vue/1.0.16/vue.js"></script>
</head>
<body>
<ul id="exampleApp">
  <li v-if="!items.length">No item found</li>
  <li v-for="item in items">
    <!--do whatever you want-->
  </li>
</ul>
<script>
var exampleApp = new Vue({
  el: '#exampleApp',
  data: {
    items: []
  }
});
</script>        
</body>
</html>

Try it »

In the above example we have initialized the items as empty object and displayed one custom message. On the same way you can check any object and display custom message.

Ouput of above example-

Vue.JS check if Object or Array is empty

Advertisements

Add Comment

📖 Read More