I have this json:
var json = {
"0":{
"check":true,
"OBJECT_ID":{
"check":false,
"name":"OBJECT_ID",
},
"nameTable":"TEST1",
"EVENT_NAME_MANAGE":{
"check":false,
"name":"EVENT_NAME_MANAGE",
}}
"1":{
"check":true,
"OBJECT_ID":{
"check":false,
"name":"OBJECT_ID",
},
"nameTable":"TEST1",
"EVENT_NAME_MANAGE":{
"check":false,
"name":"EVENT_NAME_MANAGE",
}
}
}
I would like that if I get 0 or 1, change the value of ObJECT_ID
y EVENT_NAME
totrue
I have tried doing this for :
for (var i in json) {
console.log(json[i].nameTable)
}
Depending on whether they pass me 0 or 1, I have to go through what is inside them (in my example I only have 2 ObJECT_ID and EVENT_NAME but I have many more) and change the check value inside them to true
Check the following program. It checks the existence of the property
check
of each element to assign ittrue
if it is.Based on the edit you provide me, it's more efficient to do the following:
If you receive, as you say in your question, 50 or more records, it is a waste of time to go through each and every one of the elements if you only search for two in particular, the index
0
and the1
.Let's see if I understood you correctly.
Do you want to set the check properties of the element that they indicate to true ?
If so, here is an example in which a function receives the id of the element to modify and the json object and modifies its check properties .