I have made a POST request like this:
var myHeaders = new fetch.Headers();
raw = "srvrwd-ui=useMe"
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://www.example.net", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
In console it does print the result and it comes out like this
{"totalResponse":{"details":false},"address":{"number":"234"}}
I want to get the value of number and the methods I have used to extract it specifically is the following:
.then(result => console.log(result["number"]))
which returns undefined
.then(result => console.log(result.totalResponse.address.number))
returns undefined again.
Is there any way I could get the specific value?
You are very close, totalResponse and address are two separate properties, so it would be
.then(result => console.log(result.address.number))
It would probably be beneficial for you to review this documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects as it will explain working with objects quite well.