如何删除Javascript数组中的方括号?

ngp*_*und 5 javascript jquery google-maps google-maps-api-3

我有一个调用的数组value,当我console.log(value)得到大约30行代码时,如下所示[6.443663, 3.419248]

数字随纬度和经度而变化.但我需要以某种方式摆脱每个方括号.

我试过,var replaced = value.toString().replace(/\[.*\]/g,'');但这改变了上面的例子6.443407,3.419035000000008,但我的代码失败了.

换句话说,我需要帮助摆脱数组中的方括号,以便在我的地图上绘制点.

我的数组由以下代码组成,因为每个纬度和经度值都保存onClicka链接中的函数中.所以这里的成员友好地提供了下面的代码来将我的值放到一个数组中,但现在我正在努力获取值而没有任何括号破坏它.

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])];
});
Run Code Online (Sandbox Code Playgroud)

该阵列正在尝试使用以下代码在我的Google地图上绘制标记

$.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 was not successful for the following reason: " + status);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

AUR*_*ADL 9

将行转换为数组.

var value = [[1234213, 1234231], [1234213, 1234231]];
var dato = value[0];
console.log(dato.toString());
Run Code Online (Sandbox Code Playgroud)


Gga*_*Gga 8

除非我误读并且该项是一个对象而不是包含括号的字符串,否则您可以通过其子数组poition访问它

lat = obj[this.id][0]
lng = obj[this.id][1]
Run Code Online (Sandbox Code Playgroud)

也许?


Adr*_*iro 6

看起来您想要数组的逗号分隔字符串表示形式。如果是这种情况,您可以这样做:

var commasep = value.join(",");
Run Code Online (Sandbox Code Playgroud)