Convert string with commas to array

后端 未结 18 888
执念已碎
执念已碎 2020-11-22 12:08

How can I convert a string to a JavaScript array?

Look at the code:

var string = \"0,1\";
var array = [string];
alert(array[0]);

In

18条回答
  •  粉色の甜心
    2020-11-22 12:11

    Split (",") can convert Strings with commas into a String array, here is my code snippet.

        var input ='Hybrid App, Phone-Gap, Apache Cordova, HTML5, JavaScript, BootStrap, JQuery, CSS3, Android Wear API'
        var output = input.split(",");
        console.log(output);
    

    ["Hybrid App", " Phone-Gap", " Apache Cordova", " HTML5", " JavaScript", " BootStrap", " JQuery", " CSS3", " Android Wear API"]

提交回复
热议问题