I have an array of objects in my dataset.
Here's a glimpse of how it is structured:
[
{
"id": 1,
"name": "john",
"address": { "number": 42, "street": "High Street"}
},
{
"id": 2,
"name": "jane",
"address": Null
},
{
"id": 3,
"name": "hugh",
"address": { "number": 64, "street": "Long Street"}
}
]
I am attempting to extract a list of all streets from the dataset by utilizing the following code:
const streets = this.dataset.map((d) => d.address && d.address.street).sort();
Nevertheless, I'm encountering a
cannot read property street of null
error due to instances where the address value is null.
Is there a method through which I can ignore null values when using the map function?
I've experimented with .filter(Boolean)
, but that doesn't seem to resolve the issue as the object itself isn't null.