Vue JS Convert String to Array

Posted by LaravelIndia - 4 years 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 - example.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 example.com" ,
        myResult: ''
      },
      methods:{
        clickFunction: function () {   
            this.myResult = this.myString.split(" ");
        }
      }
    })

</script>

</body>
</html>

maxwin slot mahjong ways