Vue.js check isArray


This method checks whether an object or string is array or not. We can use this method same as native JavaScript. Here in this tutorial, we are going to explain how to check an object is array or not. You can use our online editor to edit and run the code online.


Vue.js check if Object is Array Example

You can check that an object is array or not simply as below-

Example:

<div id="app">
	<p>item 1 = {{ item1 }}</p>
	<p>Result = {{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 = Array.isArray(this.item1);		
    }
	}

});
</script> 

Try it »

The above function returns true if an object is array else it will return false.

Output of above example-

Vue.js check isArray

Advertisements

Add Comment

📖 Read More