Skip to content
Advertisement

Turn a String to an array Declaration

In JS : I have this string =”[36.79025,3.01642],[36.71477,2.99761]”; I want it to be turned To a real Array =[[36.79025,3.01642],[36.71477,2.99761]]; Is this possible?

Advertisement

Answer

var string = "[36.79025,3.01642],[36.71477,2.99761]";
var arr = JSON.parse(`[${string}]`);
console.log(arr);
[[36.79025,3.01642],[36.71477,2.99761]]
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement