Vue.js string repeat


Sometimes we need to repeat string upto certain times, we can use JavaScript repeat() function to repeat string. Here in this tutorial, we are going to explain how you can use this function to repeat string in Vuejs.You can use the same method to repeat element/character in VueJs. You can use our online editor to edit and run the code online.


Vue.js string repeat Example

You repeat string in vue.js simply as below-

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",
	  result:""
  },
  
   methods:{
    myFunction: function () {	
		this.result = this.myStr.repeat(3);
    }
   }

});
</script>  

Try it »

Output of above example-

Vue.js string repeat

Advertisements

Add Comment

📖 Read More