Vue JS Convert String to Array

Posted by LaravelIndia - 1 month ago

Today 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.

Vue JS Split String Example

index.html

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

</script>

</body>
</html>