Vue.js string search


JavaScript search() method is used to search a value in a string. Here in this tutorial, we are going to explain how you can use this method to search a value in string in vuejs. You can use our online editor to edit and run the code online.


Vue.js string search Vuejs JavaScript Example

Here is an example of search method in vuejs –

Example:

<div id="app">	
	<p>{{myStr}}</p>
	<p>{{result}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  myStr:"Hello World!",
	  result:""
  },
  
   methods:{
    myFunction: function () {	
		this.result = this.myStr.search("World!");
    }
   }

});
</script>  

Try it »

If value is found in string then it will return the position of value else it will return -1.

Output of above example-


Advertisements

Add Comment

📖 Read More