Tutorialsplane

Vue.js Array IndexOf


The indexOf method is used to search an specified item in array and returns the position of item. This method returns -1 if item is not found else the position of an item. If occurrence of item is more than once, it will return the index of first index. Here in this tutorial, we are going to explain how to use indexOf Method in vue.js. You can also use our online editor to edit and run the demo online.


Vue.js Array IndexOf Method Example

Here is an example of IndexOf Method in Vue.js-

Example:

<div id="app">
	<p>item 1 = {{ item1 }}</p>
	<p>Element Index = {{elmnIndex}}</p>

	<button>Click Me</button>
</div>
 

Try it ยป

Output of above example-