Vue.Js string endsWith


Vue.Js string endsWith We can use native JavaScript method endsWith to check whether a string ends with the specified string or character. Here in this tutorial, we are going to explain how you can check whether a string ends with specified character or not.


Vue.Js string endsWith Example

You can check whether an string ends with specified chars/string simply as below-

Example:

<!DOCTYPE html>
<html>
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
</head>
<body>
<div id="app">
	{{result}}
</div>
<script>
new Vue({
el: '#app',
  
  data: { 
	  str:"Hello World!",
	  result: ''
  },
  
   methods:{
    checkEndswith: function () {
      var v = this;
	  var r = v.str.endsWith("World!");
	  if(r){
		v.result = "Ends with - World!";  
	  }
    }
	},
  mounted () {
  this.checkEndswith();
}

});
</script>     
</body>
</html>

Try it »

Output of above example-

Vue.Js string endsWith Example

Advertisements

Add Comment

📖 Read More