Vue JS Convert String to Array Example
Hi Guys,
Today, I will learn you how to convert string to array in vue js.i will show you how to convert string to array using split() in vue js. i will give simple example of split string with space, comma, semicolon etc in vuejs.
If you worked with javascript then you know split() and how it use. The split() method is used to split the string into an array of the substring and returns a new collection array. you can see bellow following syntax:
myArray.split(separator);
Here i gave you simple example of convert string into an array with space. i will also show you output of array, so you can understand how it works.
Example
<!DOCTYPE html>
<html>
<head>
<title>Vue JS Convert String to Array Example - nicesnippets.com</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<p>String : {{ myString }}</p>
<p>Array : {{myResult}}</p>
<button @click="clickFunction()">Click Me</button>
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
myString: "This is Nicesnippets.com" ,
myResult: ''
},
methods:{
clickFunction: function () {
this.myResult = this.myString.split(" ");
}
}
})
</script>
</body>
</html>
OutPut
String : This is Nicesnippets.com
Array : [ "This", "is", "Nicesnippets.com" ]
It will help you..
- How to Build VUE JS CRUD Using Node js Express and MySQL?
- Vue js File Upload Axios Php Example
- Vue Js Application Check Current Version In Ubuntu
- Vue JS Get Array Length Or Object Length Tutorial
- Vue JS Download File using Axios Example
- Vue JS Declare Global Variable Example
- Vue Js Sweetalert Modal Notification Tutorial
- Vue Js Get Element By Id Example