How to push data to a nested Object

后端 未结 5 804
醉梦人生
醉梦人生 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:43

    dot operator(.) can be used to get the value of a particular object property.

    square brackets ([]) can be used to access an element of an array.

    Now the answer to your question:

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

    here, [0] specifies the first element of your array.

提交回复
热议问题