I'm facing a minor challenge in formatting my arrays into the desired JSON structure. Here's the code I've used:
var arrData = [{label:Test,value:199.12}, {label:Test2,value:1024}]
var data = [];
for (var i = 0; i < arrData.length; i++) {
data.push(JSON.stringify({
label: arrData[i][2],
value: arrData[i][3]
}).replace(/\"/g, "").replace("\\r", ""))
}
The code above works as expected. However, I'd like to reformat it to match the following structure:
{ label: 'Food', value: 90 },
In this format, I want the label data enclosed in single quotes and remove the double quotation marks surrounding the JSON. Currently, my JSON looks like this:
"{label:Test,value:199.12}", "{label:Test2,value:1024}",