Vue Js String Includes Method:Vue.js string includes is a function that allows you to search for a given string within another string.The includes() method uses a case-sensitive search to determine whether one string might be contained by another, returning true or false depending on the situation.In this tutorial, we’ll go over how to find substrings using Vue.js’s includes method.
String can be checked to see if a substring is present in Vue.Js
Vue.js provides a variety of methods for searching and manipulating strings, including the “includes()” method, which can be used to check whether a given substring is present in a string.
Vue js string contains substring Example True
<div id="app">
<p>{{string}}</p>
<button @click="myFunction">click me</button>
<p>{{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
string : 'SarkariNaukariExams',
substring:'Exams',
results:""
}
},
methods:{
myFunction(){
this.results = this.string.includes(this.substring);
},
}
}).mount('#app')
</script>
Output of above example
Starting the search character within string in Vue at position 7
The search in Vue.js can be done using position 7 as the starting point
Vue js Check if given words are present in a string
<div id="app">
<p>{{string}}</p>
<button @click="myFunction">click me</button>
<p>{{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
string : 'TutorialsPlane',
substring:'Plane',
results:""
}
},
methods:{
myFunction(){
this.results = this.string.includes(this.substring,9);
},
}
}).mount('#app')
</script>