I'm getting string from database and i need to convert it in the format below:
var locations = [
["LOCATION_1", 11.8166, 122.0942],
["LOCATION_2", 11.9804, 121.9189],
["LOCATION_3", 10.7202, 122.5621],
["LOCATION_4", 11.3889, 122.6277],
["LOCATION_5", 10.5929, 122.6325]
];
my code below
var array = ''
var arrayprev= ''
for (var i = 0; i < obj.length; i++) {
array = '['+obj[i].Location + '"' + ',' + obj[i].x + ',' + obj[i].y + '],|'
if (arrayprev == "") {
arrayprev = array;
}
else {
arrayprev = arrayprev + array;
}
}
locations = arrayprev.split("|")
i'm getting only chracters when passing in code below
for (var i = 0; i < locations.length; i++) {
marker = new L.marker([locations[i][1], locations[i][2]], { icon: iconColor(color) })
// PoPup result will be displayed here
.bindPopup(locations[i][0])
//here tool tip will be used to display the label text
.bindTooltip(locations[i][0],
{
permanent: true,
direction: 'right'
}
)
.addTo(map);
hardcoded location array is working fine but when I use my loop I'm not getting the correct data Please help
array = '['+obj[i].Location + '"' + ',' + obj[i].x + ',' + obj[i].y + '],|'