Reputation: 1
I am trying to reach out to the "testdata":"two" property values [like 'EH']. While I was taking that property, I am facing "Cannot read property" this issue, How I fix this issue in Cypress?
[{
"testdata": "one",
"TC": {
"EHQ0": "Address",
}
},
{
"testdata": "two",
"TC": {
"EH": "Student",
"E1": "Question For Name",
"EnglishText_E1": "Question For Name"
}
}
]
Upvotes: 0
Views: 167
Reputation: 147
You have an array of objects, so either index or find.
const data = [{
"testdata": "one",
"TC": {
"EHQ0": "Address",
}
},
{
"testdata": "two",
"TC": {
"EH": "Student",
"E1": "Question For Name",
"EnglishText_E1": "Question For Name"
}
}
]
const objTwo = data.find(obj => obj.testdata === 'two')
const ehProp = objTwo.TC.EH
Upvotes: 2