Sol Sol - 1 year ago 52
Javascript Question

How do you replace characters in Javascript?

How can you in Javascript replace characters? I need to replace '(' and ')' in this output to make this link work correctly. Jquery would be ok too, but Javascript is usually faster on it's own.

function success(position) {
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var latlng1 = latlng.replace('(', '');
var latlng1 = latlng1.replace(')', '');


For example my output of latlng (latitude, longitude) would show the ( ) in it:


Answer Source

You could try the following regex

 var latLng = "(48.6617564,-102.98313889933997)",
    latLng = latLng.replace(/([()])/g, '');