Vue JS Convert String to Array

Vue JS Convert String to Array


In this tutorial we will learn how to convert strings into arrays and having multiple select box.

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 sub-string and returns a new collection array. you can see bellow following syntax:



This is how my returned data from back-end looks like and I want to split it.

tags: "tag1,tag2,tag3"


    export default {
        data() {
            return {
                form: {
                    seoTags: []
        mounted() {
        methods: {
            fetchTags() {
                .then(response => {
                    this.form.seoTags =",")
                .catch(function (error) {
                    console.log('errors: ', error);

As you can see I have split my tags based on comma (,) in between then there for I would get array of each of them. Here is the results

Easy right? :)

- Last updated 3 years ago

Be the first to leave a comment.

You must login to leave a comment