0

Let's say I have the following variable:

var myString='Description=TEST DESC&Stuff=things&Quantity=2';

How can I get the different items from this variable using split? So there are multiple values, and the format is always the same:

variable=result and then followed by ampersand, then next variable=result.

I need to be able to assign each of those to actual variables

Description=TEST DESC;
Stuff=things;
Quantity=2;

Any help?

Josh S
  • 1
  • 2
  • 1
    http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – Victor Levin Dec 10 '15 at 21:36
  • http://stackoverflow.com/questions/9406738/javascript-separate-string-into-different-variables – Andy Dec 10 '15 at 21:37
  • That looks like a query string, so the answers in the duplicate apply (the only difference is that you want to use `myString` instead of `location.search` or `location.href` – Paul Dec 10 '15 at 21:37
  • you would have to store these values in an object. you could use one of the solutions mentioned above – pizzarob Dec 10 '15 at 21:37
  • I wrote an answer there that would work as a drop-in if you delete the line `var url = location.search;` and take in an argument for `url` instead (appropriate renaming would be advised) http://stackoverflow.com/a/12197444/772035 – Paul Dec 10 '15 at 21:39
  • There are a bazillion string parsing q&a on SO. I'll leave it to you to search one out and close this question. – isherwood Dec 10 '15 at 21:39

0 Answers0