I have this ajax function returns data as in plain text form.
$.ajax({
type: 'GET',
url: "/addObstacles",
cache: false,
datatype: "text/plain",
success: function (data) {
var obstacles = data.split('\n');
for(var i = 0;i < obstacles.length;i++){
if(!obstacles[i] == ''){
console.log(obstacles[i]);
}
}
}
});
console.log(obstacles[i]):
[[90, 90], [90, 112], [100, 112], [100, 100], [200, 100], [200, 125], [240, 125], [240, 121]]
I want to get rid of all square brackets and the commas after every element and it should look like this:
90,90 90,112 100,112 100,100 200,100 200,125 240,125 240,121
As this data will be the points for drawing a SVG polyline dynamically. I tried many regex and strip() but no luck.
obstacles[i].replace(/(\[.*?\])/g, '');,obstacles[i].replace(/ *\[[^\]]*]/g, '');I tried these..replace(/\[|\],|\]/g, '').