Vue JS Convert String to Array | Vue JS Split String Example

Vue JS Convert String to Array | Vue JS Split String Example

In this post we will show you Vue JS Convert String to Array | Vue JS Split String Example, hear for Vue JS Convert String to Array | Vue JS Split String Example we will give you demo and example for implement.

Today We will show you how to convert string to an array using split() in vue js. I will give a simple example of a split string with space, comma, semicolon, etc in vuejs.

If you worked with javascript then you know split() and how it uses. 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);

bellow I gave you simple example of convert string into an array with space. i will also show you the output of the array, so you can understand how it works.

Example:

<!DOCTYPE html>
<html>
<head>
    <title>Vue JS Convert String to Array | Vue JS Split String Example - onlinecode</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 onlinecode" ,
        myResult: ''
      },
      methods:{
        clickFunction: function () {   
            this.myResult = this.myString.split(" ");
        }
      }
    })
   
</script>
   
</body>
</html>

Output:

String : This is onlinecode

Array : [ "This", "is", "onlinecode" ]</pre>

Hope this code and post will help you to implement Vue JS Convert String to Array Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

1 thought on “Vue JS Convert String to Array | Vue JS Split String Example”

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  4  =  9

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US