Vue.Js Convert string to Array


We can use native JavaScript split() method to convert string to array in vue.js. Here in this tutorial, we are going to explain how you can convert a string to Array in Vue.js.


Vue.Js Convert string to Array JavScript Example

Here is an example of split method in Vue.js-

Example:

<pre>
<!DOCTYPE html>
<html>
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
</head>
<body>
<div id="app">
	<p>String = {{ str }}</p>
	<p>Array = {{result}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  str:"Hello World! Welcome Greenland.",
	  result:''
  },
  
   methods:{
    myFunction: function () {		
		this.result = this.str.split(" "); // split at blank space
		
    }
	}

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

Try it »

Output of above example-

Vue.Js Convert string to Array

Advertisements

Add Comment

📖 Read More