I have a function like this where I’m dynamically generating the option tag of a select.
function colorInfo(data) {
console.log("Color Info");
console.log(data);
let colorData = JSON.parse(data);
console.log(colorData);
$.each(colorData, function (key, value) {
$("#lineupColors").append(
$("<option></option>")
.attr("value",'{"colorId":'+value.colorId+',"colorCode":'+value.colorCode+'}')
.text(value.colorName)
);
});
}
Since I am defining the value as a Json object, how can I add double quotes such that the value would look like {"colorId":"1","colorCode":"#FFFFFF"}
.
Right now it is coming out like this – which is not a valid JSON :
{"colorId":1,"colorCode":#FFFFFF}
.