javascript - How to push data to a nested Object -


how can push element variables property below object?

  var request = {     "name": "name",     "id": 3,     "rules":[       {         "name": "rule name",         "tags": [           {             "tagid": 1,             "variables":[               {                 "variable": "var1",                 "matchtype": "regex",                 "value": ".*"               },               {                 "variable": "var2",                 "matchtype": "regex",                 "value": ".*"               }             ],             "condition": false,           },           {             "tagid": 1,             "condition": false,           }         ],         "rulesetid": 3,       }     ]   } 

for exaple, need add {"variable": "var3", "matchtype": "regex", "value": ".*"} variables property request object...how can this?

for(i=0;i<duplicates.length; i++) {   var request = {     "name": duplicates[i].scope,     "id": 3,     "rules":[       {         "name": duplicates[i].scope + " " + "op sdr sync",         "tags": [           {             "tagid": 1,             "variables":[               {               }             ],             "condition": false,           },           {             "tagid": 1,             "condition": false,           }         ],         "rulesetid": 3,       }     ]   }    request.rules[0].tags[0].variables[0].push({     "variable":"var3",     "matchtype": "regex",     "value": ".*"   }); } 

you have "navigate" in object:

request.rules[0].tags[0].variables.push({   "variable":"var3",   "matchtype": "regex",   "value": ".*" }) 

request['variables'] try find variables key in root of request object. key not defined nested in object/array structure.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -