'Composing an axios url with a value that contains the character & in it

I´m programming a call with axios.get with an url that is similar to:

http://example.com/path?element1={example1}&element2={example2}&element3={function(query)}

function ((condition1: string, condition2: string) => {
  query = "";
  if(condition1 is x){
    query = "&condition1" + condition1;
  }
  if(condition2 is x){
    query = "&condition2" + condition2;
  }
)

If the value in condition1 or in condition2 is something like: "bananas" it works perfectly.

But the problem is that if the value in condition1 or in condition2 is something like "bananas & potatoes"

Whe it comes to the back end its something like:

condition1: {"bananas ", " potatoes"}

instead of

condition1: "bananas & potatoes"

If you know why this can be happening or what am i doing bad please let me now.

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source