0

Below json we are getting in response, and to this api we need to add new element for all input parameter array and send new request to server.

How to push "inputList":[ ] element below all array elements of inputParameters?

Response:

{
   "canBeSubscribed":false,
   "inputParameters":[
      {
         "allowBlank":false,
         "canBeShownOnUi":false,
         "uiControl":"1"
      },
      {
         "allowBlank":false,
         "uiControl":"1"
      }
   ],
   "reportTitle":"Report"
}

New Request:

{
   "canBeSubscribed":false,
   "inputParameters":[
      {
         "allowBlank":false,
         "canBeShownOnUi":false,
         "uiControl":"1",
         "inputList":[
            
         ]
      },
      {
         "allowBlank":false,
         "uiControl":"1",
         "inputList":[
            
         ]
      }
   ],
   "reportTitle":"Report_New"
}
1
  • 1
    JSON is a textual notation for data exchange. (More here.) If you're dealing with JavaScript source code, and not dealing with a string, you're not dealing with JSON. Commented Apr 7, 2022 at 11:25

1 Answer 1

1

const response = {
   "canBeSubscribed":false,
   "inputParameters":[
      {
         "allowBlank":false,
         "canBeShownOnUi":false,
         "uiControl":"1"
      },
      {
         "allowBlank":false,
         "uiControl":"1"
      }
   ],
   "reportTitle":"Report"
}

const newRequest = {
  ...response,
  reportTitle: "Report_New",
  inputParameters: response.inputParameters.map((inputParameter) => ({
    ...inputParameter,
    inputList: [],
  }))
}

console.log(newRequest);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.