I am getting a set of Arrays in string format from Database like
["#464b4e","#7ebcbd"], ["#747493","#f5f6f7"], ["#58383c","#8d8566"]
Now I need to load them into array to make an array of arrays. Using this code
let imgIndicators = [];
imgIndicators.push( obj[i]['dicatorsbg']);
console.log(imgIndicators);
is creating an array like
["["#464b4e","#7ebcbd"], ["#747493","#f5f6f7"], ["#58383c","#8d8566"]"]
which as you can see is big long string item, so I tried splitting the data by , like
imgIndicators.push( obj[i]['dicatorsbg'].split(','));
This time code is accepting all , and creating an array of 6 string elemet like
["["#464b4e"", ""#7ebcbd"]", " ["#747493"", ""#f5f6f7"]", " ["#58383c"", ""#8d8566"]"]
How can I fix this code to create something like this?
[
["#464b4e", "#7ebcbd"],
["#747493", "#f5f6f7"],
["#58383c", "#8d8566"]
]
'dicatorsbg'coming from?echo json_encode($products);JSON.parseworks for you or just taking the string as is into the javascript part? - with maybe wrapped into brackets? but if the last part is necessary, you do not have a valid JSON.