Ive been reading semilar questions and answers trying to get a solution to this, im working on maps and getting strings that I have to convert to arrays... I got an string that's given to me as variable that I have access on it as string:
coords = '[42.46329472141537,21.46498522471254],[42.463191829327116,21.4654574564449],[42.463524249310545,21.465586246917347],[42.463642970305486,21.465092550106277]';
I need this variable to be an array, I tried JSON.parse it's throwing me an error, I tried to map(Number) that's not defined and Ive tried to split, it's deforming my array... As result I need the array to be in this format:
var newCoords = Array(Array([42.46329472141537,21.46498522471254]),Array([42.463191829327116,21.4654574564449]),Array([42.463524249310545,21.465586246917347]),Array([42.463642970305486,21.465092550106277]));
Every advice will be helpful.
JSON.parse(`[${coords}]`);JSON.parse("[" + coords + "]");and this just wraps the string in square brackets to have a valid JSON.