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

后端 未结 17 2465
误落风尘
误落风尘 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:38

    This isn't as good as the destructuring answer, but seeing as this question was asked 12 years ago, I decided to give it an answer that also would have worked 12 years ago.

    function Record(s) {
        var keys = ["name", "address", "address2", "city", "state", "zip"], values = s.split("~"), i
        for (i = 0; i

提交回复
热议问题