jquery - How to remove square brackets in a Javascript array? -
i have array called value
, when console.log(value)
30 lines of code following [6.443663, 3.419248]
the numbers change latitudes , longitudes. need somehow rid of square brackets around each one.
i tried var replaced = value.tostring().replace(/\[.*\]/g,'');
changed above example 6.443407,3.419035000000008
, failed code.
in other words need getting rid of square brackets in array in order plot points on map.
my array made following code because each latitude , longitude value held within onclick
functions within a
links. member on here kindly supplied below code values array i'm struggling values out without brackets ruining it.
var obj = {}; $('.choice-location-inner a').each(function(){ var $this = $(this); var text = $this.attr('onclick').replace('findlocation(\'', '').replace('\');return false;', ''); var array = text.split(',') obj[this.id]= [parsefloat(array[0]), parsefloat(array[1])]; });
the array trying plot markers on google map using following code
$.each(obj , function(index, value){ geocoder = new google.maps.geocoder(); geocoder.geocode( { 'address': value}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); marker = new google.maps.marker({ map: map, icon: image, position: results[0].geometry.location }); } else if (status == google.maps.geocoderstatus.over_query_limit) { wait = true; settimeout("wait = false", 1000); } else { alert("geocode not successful following reason: " + status); } }); });
unless i've misread , item object rather string brackets contained, access sub array poition
lat = obj[this.id][0] lng = obj[this.id][1]
perhaps?
Comments
Post a Comment