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
Since the splitting on commas question is duplicated to this question, adding this here.
If you want to split on a character and also handle extra whitespace that might follow that character, which often happens with commas, you can use replace
then split
, like this:
var items = string.replace(/,\s+/, ",").split(',')