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?

6
  • 1
    stackoverflow.com/questions/901115/… Commented Dec 10, 2015 at 21:36
  • stackoverflow.com/questions/9406738/… Commented Dec 10, 2015 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 Commented Dec 10, 2015 at 21:37
  • you would have to store these values in an object. you could use one of the solutions mentioned above Commented Dec 10, 2015 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) stackoverflow.com/a/12197444/772035 Commented Dec 10, 2015 at 21:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.