So, I'm struggling to get the data called otherPartyName
. This data is fetched from a WebAPI and this is stored in a local state called dataSource
. I am using react native and would like to check whether the latest createdBy is equal to otherPartyName. I am able to get the name of createdBy
, but am unable to get the value of otherPartyName as I kept getting undefined
.
dataSource
Array [
Object {
"comment": "Min vintage",
"feedbackId": 32,
"otherPartyName": "DooDooDooDooDoo",
"replies": Array [
Object {
"comments": "Bruh ",
"createdBy": "Min Cunt",
"feedbackLogId": 32,
"feedbackReplyLogId": 4,
},
Object {
"comments": "So this is 1",
"createdBy": "Min Cunt",
"feedbackLogId": 32,
"feedbackReplyLogId": 5,
},
],
"sender": "43434343",
"type": "Improvement",
},
]
This is how i get the value of latest createdBy
.
let totalCount = dataSource.reduce((a, c) => a + c.replies.length, 0);
let reply = dataSource.map(({ replies }) => replies[totalCount - 1].createdBy)
But whatever I do, I'm getting undefined for otherPartyName
let otherParty = dataSource.otherPartyName
let otherParty = dataSource[0].otherPartyName
let otherParty = dataSource.map(({ otherParty }) => otherParty.otherPartyName)
if i do console.log(dataSource)
, I am able to get dataSource shown above as the result, but why am i getting undefined, if i do console.log(dataSource.otherPartyName)