Looking to update the content_available value to true for codes EN and CN in a JSON object. Here is the attempted solution:
myObj = { "data": [{ "code": "EN", "language": "English", "content_available": true, "isdefault": true }, { "code": "AR", "language": "Arabic", "content_available": true, "isdefault": false, "default" : true
}, {
"code": "BR",
"language": "Brazilian Portuguese",
"content_available": true,
"isdefault": false
}, {
"code": "CN",
"language": "Simplified Chinese",
"content_available": true,
"isdefault": false,
"default" : true
}, {
"code": "TW",
"language": "Traditional Chinese",
"content_available": true,
"isdefault": false
}, {
"code": "DE",
"language": "German",
"content_available": true,
"isdefault": false
}, {
"code": "ES",
"language": "Spanish",
"content_available": true,
"isdefault": false
}, {
"code": "FR",
"language": "French",
"content_available": true,
"isdefault": false
}, {
"code": "JP",
"language": "Japanese",
"content_available": true,
"isdefault": false,
"default" : true
}, {
"code": "RU",
"language": "Russian",
"content_available": false,
"isdefault": false
}],
"success": true
}
function setContentAvailable() {
for (var key in myObj.data) {
if (myObj["data"]["code"] === "EN" && myObj[data][code] === "CN") {
myObj.data.content_available = false;
}
}
}
setContentAvailable();
console.log(myObj);