Javascript is returning an extra space, please help!

I have a working script here that was generated to return addresses with superscripts. however it is returning an unnecessary space… please see script below.

function prepFormat3(test3) {
  if (!test3) return '';

  var output3 = '';
  var placeholder3 = '';
  
  var b = test3.split(" "),
  
  i3=0;
  
  
  for (i3 = 0; i3 <= b.length-1; i3++) {
    if (b[i3].match(/^\d/)){
      
      if (b[i3].indexOf('TH')>=0){
        placeholder3= b[i3].split("TH");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">TH</_char>";
      }
      if (b[i3].indexOf('Th')>=0){
        placeholder3= b[i3].split("Th");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">TH</_char>";
      }
      if (b[i3].indexOf('th')>=0){
        placeholder3= b[i3].split("th");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">TH</_char>";
      }
      
      if (b[i3].indexOf('RD')>=0){
        placeholder3= b[i3].split("RD");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">RD</_char>";
      }
      if (b[i3].indexOf('rd')>=0){
        placeholder3= b[i3].split("rd");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">RD</_char>";
      }
      if (b[i3].indexOf('Rd')>=0){
        placeholder3= b[i3].split("Rd");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">RD</_char>";
      }
      
      if (b[i3].indexOf('ST')>=0){
        placeholder3= b[i3].split("ST");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">ST</_char>";
      }
      if (b[i3].indexOf('st')>=0){
        placeholder3= b[i3].split("st");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">ST</_char>";
      }
      if (b[i3].indexOf('St')>=0){
        placeholder3= b[i3].split("St");
        b[i3]=placeholder3[0] + "<_char line_break_penalty_degree=\"boolean\" supersub=\"superscript\">ST</_char>";
      }

    }
    
    if (b[i3].indexOf('*') >=0){
      placeholder3= b[i3].split("*");
      b[i3]= "<_char  bold=\"false\" italic=\"true\" case=\"unchanged\">"+placeholder3[1]+ " </_char>";
    }
    
    if (b[i3].indexOf('^') >=0){
      placeholder3= b[i3].split("^");
      b[i3]= "<_char  bold=\"false\" italic=\"true\" case=\"upper\">"+placeholder3[1]+ " </_char>";
    }
    
    
    b[i3];

    output3 += b[i3] + " ";

  }
  
  return output3;

}

function supSciptFormat(test3) {
  if (!test3) return '';  
}

@anthony7 Could you please clean up your code? Fix the indenting, remove superfluous commented out bits, add explanatory comments if necessary, and then wrap the whole thing in rows of backticks(```), like this:

```
your code here
```

@lionel-rowe
My apologies, I am really not a code savy person, but I will do the best I can…

hows this?

[edited into first post - lr]

Think of arr.join(<joiner>) => str as the reverse operation to str.split(<splitter>) => arr. Then try initializing output to an empty array, pushing to that array, and then returning the joined array at the end.