Vue Js String Repeat Method:Vue Js String Repeat Method: Vue.js allows us to use the JavaScript string method “repeat” to repeat a specified string a given number of times This is useful for creating strings with repetitive elements, such as filling a string with a certain number of spaces or repeating a character to create horizontal lines It creates a new string that contains the specified number of copies of the string on which it was called In Vue.js, you can repeat an element or character using the same technique. With this editor, you can write and debug your code in one place.
How to make a copy of a string in Vue Js?
In Vue.js, a copy of a string can be made using the String.prototype.repeat() method, which returns a copied string a given number of times.
Vue Js Create copies of a string
<div id="app">
<button @click="myFunction">click me</button>
<p>Text: {{text}}</p>
<p>Copied text:{{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
text : 'Vue Js tutorials: learn vue tutorials the easy way here. ',
results:''
}
},
methods:{
myFunction(){
this.results = this.text.repeat(2);
},
}
}).mount('#app')
</script>
Output of above example
How to Repeat 5 times a String in Vue js?
The string repeated however many times are required is returned by the VueJS string repeat() method.
Vue Js String Repeat Method
<div id="app">
<button @click="myFunction">click me</button>
<p>Text: {{text}}</p>
<p>Copied text:{{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
text : 'Font Awesome Icons',
results:''
}
},
methods:{
myFunction(){
this.results = this.text.repeat(5);
},
}
}).mount('#app')
</script>