I have a complex JS array of objects and properties. Some of them return value but some return null, the problem is when I am mapping through the list it causes error whenever there is a null value.
I cannot filter out the array right now because I am already inside a loop and should not create another filtered array. What would my best approach be? I want my loop to return Array.Group.name[0].text and if it is not there just return null.
const x = [
{
"id": "1",
"Groups": [
{
"name": [
{
"language": "en-US",
"text": "REGULAR_TIME"
}
],
"isSystem": true
},
{
"name": [
{
"language": "en-US",
"text": "CHARGEABLE"
}
],
"isSystem": true
}
]
},
{
"id": "2",
"Groups": [
{
"name": [
{
"language": "en-US",
"text": "REGULAR_TIME"
}
],
"isSystem": true
},
{
"name": [
{
"language": "en-US",
"text": "CHARGEABLE"
}
],
"isSystem": true
}
]
}
]
x.map(y=>y.Groups.name[0].text)
console.log(x)