How do I split a string, breaking at a particular character?

后端 未结 17 2392
误落风尘
误落风尘 2020-11-21 05:07

I have this string

\'john smith~123 Street~Apt 4~New York~NY~12345\'

Using JavaScript, what is the fastest way to parse this into



        
17条回答
  •  情书的邮戳
    2020-11-21 05:34

    Zach had this one right.. using his method you could also make a seemingly "multi-dimensional" array.. I created a quick example at JSFiddle http://jsfiddle.net/LcnvJ/2/

    // array[0][0] will produce brian
    // array[0][1] will produce james
    
    // array[1][0] will produce kevin
    // array[1][1] will produce haley
    
    var array = [];
        array[0] = "brian,james,doug".split(",");
        array[1] = "kevin,haley,steph".split(",");
    

提交回复
热议问题