I'm trying to join a list of latLng
values which are stored in an array like this:
"48.2025,16.3687","48.2437,16.3797"
Instead, I keep getting output like this:
"48.2025,16.3687,48.2437,16.3797"
This is the code that I'm using:
$(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]));
});
});
This should help :)
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"'
您可以这样做以获得输出
var fullArray = "\"" + printPoints.join("\",\"") + "\"";
If you want single line, use this:
const values = ["48.2025,16.3687", "48.2437,16.3797"]; console.log(values.map(value => `"${value}"`).join());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.