0

我正在尝试加入latLng存储在这样的数组中的值列表:

"48.2025,16.3687","48.2437,16.3797"

相反,我不断得到这样的输出:

"48.2025,16.3687,48.2437,16.3797"

这是我正在使用的代码:

$(document).ready(function()
    {

    $('#printMapLatLng').click(function()

        {
            var printPoints = [];
            for (var i in points) {
                var input = points[i].LatLng.toString();
                var output = ''+input.replace( /\s/g, "").slice(1,-1)+'';
                printPoints.push(output);
            }         
                var fullArray = printPoints.join();
                $(this).attr('href',PowerHour.getPrintUrl([fullArray]));
        });
});
4

3 回答 3

3

如果你想要单行,使用这个:

const values = ["48.2025,16.3687", "48.2437,16.3797"];

console.log(values.map(value => `"${value}"`).join());

于 2020-06-23T23:48:00.477 回答
2

这应该有帮助:)

var points = ["48.2025,16.3687","48.2437,16.3797"];
points.map(function(p){ return '"' + p + '"'; }).join(',');
// => '"48.2025,16.3687","48.2437,16.3797"'
于 2013-07-08T16:25:41.220 回答
1

你可以这样做来获得输出

var fullArray = "\"" + printPoints.join("\",\"") + "\"";
于 2013-07-08T16:06:33.610 回答