I have a text file in this format:
[[Line1TextA,[Lat,Long]], [Line1TextB,[Lat,Long]], ...]
[[Line2TextC,[Lat,Long]], [Line2TextD,[Lat,Long]], ...]
.
.
.
I am parsing a text file (done) and I want to convert strings in array format into actual array and store them as a variable to use.
I tried to use JSON.parse, as suggested here: Convert string containing arrays to actual arrays but I couldn't get it to work (syntax errors). Here is my attempt: https://jsfiddle.net/5yz95ktg/
var myStr = '[[Line1TextA,[Lat,Long]], [Line1TextB,[Lat,Long]]]'
var myArr = JSON.parse(myStr);
var myArr = JSON.parse("[" + myStr + "]");
Edit:
function readFile(query) {
$.get('file.txt', function(data) {
var lines = data.split("\n");
for (var i = 0, len = lines.length; i < len; i++) {
if (lines[i].indexOf(query) > -1) { // Found a match
var myArr = JSON.parse(lines[i]); // #NOT WORKING
}
}
});
}