How to dynamically modify an API response

Viewed 34

I have an API that I am using however to get it to display I'm using:

`<div>${JSON.stringify(response)}</div> `

to get the the API endpoint to display and this works fine. However this results in an output like

{xxx:more text here}

The thing is I only want the more text here to be displayed so I use response.xxx and this works however how do I dynamically change the xxx in java script. So with a button click or some such action I can change the xxx so on the button click response.xxx can become response.yyy.

Any help will be greatly appreciated.

1 Answers

Building on what was said by gvmani simply add a place holder value to the response thus:

<div>${JSON.stringify(response)}</div>

becomes:

<div>${JSON.stringify(response[xxx])}</div>

where I can change the value of xxx to any other as needed.

Related