Skip to main content
2 of 3
Removed closing paragraph (I feel asking for a specific issue about your code makes it off-topic)

reformatting string to two string values in javascript

I have the following code that converts a string that looks like aaa-bbb|ccc-ddd|eee-fff to two strings that look like aaa|ccc|eee and bbb|ddd|fff.

        var id = "HEL-CAS|MAD-STO|XXX-YYY" 
        var splittedId = id.split('|');
        var from = "", to = "";
        $(splittedId).each(function(a,b) {
            from = from + b.split("-")[0]+"|";
            to = to + b.split("-")[1] + "|";
        });
        from = from.substring(0,from.length-1);
        to = to.substring(0,to.length-1);
najib
  • 21
  • 1