How to use .replace in Javascript? -


i have javascript using on site automatically generates breadcrumbs based on file structor. problem having names displays based on file names, , times names have under scores in them. here example:

home / marketing / news_events / news & events home page

what remove under score in news_events , replace space... same bread crumbs on site.

my java script not think have add this:

string.replace(/_/g,' ');

i'm not sure or how place in javascript.

here full javascript:

	  		function breadcrumbs(){    surl = new string;    bits = new object;    var x = 0;    var stop = 0;    var output = '<a href="/"><i class="fa fa-home fa-lg"></i></a> &nbsp;/&nbsp; ';     surl = location.href;    surl = surl.slice(8,surl.length);     chunkstart = surl.indexof("/");    surl = surl.slice(chunkstart+1,surl.length)    while(!stop){      chunkstart = surl.indexof("/");      if (chunkstart != -1){        bits[x] = surl.slice(0,chunkstart)        surl = surl.slice(chunkstart+1,surl.length);      }else{        stop = 1;      }      x++;    }    for(var in bits){      output += "<a href=\"";      for(y=1;y<x-i;y++){        output += "../";      }      output += bits[i] + "/\">" + bits[i] + "</a> &nbsp;/&nbsp; ";    }    document.write(output + document.title);  }  		

any appreciated!

you need replace line, bits[i] has underscores replaced:

output += bits[i] + "/\">" + bits[i] + "</a> &nbsp;/&nbsp; ";

turns into:

output += bits[i] + "/\">" + bits[i].replace(/_/g,' ') + "</a> &nbsp;/&nbsp; ";


Comments