String replace "<br> β΅" with commas in javascript array
I get the following character when I print my array to the console: " <br>β΅ "
How to replace all instances of " <br>β΅ " with commas in a JS array?
eg.
["767 5th Ave<br>β΅New York, NY 10153, USA", "677 5th Ave<br>β΅New York, NY 10022, USA"] to
["767 5th Ave, New York, NY 10153, USA", "677 5th Ave, New York, NY 10022, USA"] The value is taken from:
<address class="main"> <p>767 5th Ave<br> New York, NY 10153, USA</p> </address> with the following code:
$("address.main p:not(:empty)").each(function() { addresses_google[0].push( $(this).html() ); }); +5
1 answer
var addresses = ["767 5th Ave<br>β΅New York, NY 10153, USA", "677 5th Ave<br>β΅New York, NY 10022, USA"]; var formattedAddresses = addresses.map(function(str) { return str.replace(/<br>\u21b5/g, ", "); }); console.log(formattedAddresses); Update:
It seems that html is placed in this array with line breaks (interpreted as the β΅-characters used to render a new line) compared to ordinary line literals.
$("address.main p:not(:empty)").each(function() { addresses_google[0].push( $(this).html() ); }); Now that we know that this is the result of a loop, we could do all of this inside this loop of the loop code without having to create a new array:
$("address.main p:not(:empty)").each(function() { var breaks = /<br>(\r\n|\n|\r)/gm; var formattedHTML = this.innerHTML.replace(breaks, ', '); addresses_google[0].push(formattedHTML); }); +4