How to push data to a nested Object

后端 未结 5 760
醉梦人生
醉梦人生 2021-01-17 02:48

How can I push another element to the variables property from the below object?

  var request = {
    \"name\": \"Name\",
    \"id\": 3,
    \"r         


        
5条回答
  •  情话喂你
    2021-01-17 03:28

    You have to "navigate" properly in your object:

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

    request['variables'] will just try to find the variables key in root of the request object. This key is simply not defined but is nested in your object/array structure.

提交回复
热议问题