I am looking to return a string if a key isnt avaiable within a map function. This is my current function, where sometimes it would be unable to find the key edBidResponse and return an Error.
const winCpm = () => {
return data.map((result) => result.response.response.edBidResponse.responseObject.winCpm);
};
When an API is called sometimes .result.response.response. will not have an edBidResponse object. As an example shows...
With
id like to return data.map((result) => result.response.response.edBidResponse....
"response": {
"response": {
"defLevel": "xxxx",
"reason": "yyy",
"edBidResponse": { ...
Without
Id like to return a string "Empty Value" For each value where edBidResponse was not present.
"response": {
"response": {
"defLevel": "xxx",
"reason": "yyy",
"logEvent": [...
I have tried many if statements but nothing seems to click, i have read some SO stuff on reduce but never used that. Any tips would be appreciated.