Let's say we have array of objects:
const data = [
{
firstName: "Bruce",
lastName: "Wayne",
address: "Arkham 6",
id: "1",
},
{
firstName: "Peter",
lastName: "Parker",
address: "LA 54",
id: "2"
},
{
firstName: "Tony",
lastName: "Stark",
address: null,
id: "3"
}
];
and want to get length of the array but exclude counting of the objects which has null values (in example above, this is the last object with address property null) so that result of the counting of the example above would be 2.
objectsWithoutNull = data.reduce(function (r, a) {
return r + +( a!== null);
}, 0);
I'm trying with reduce method, but got 0. Where is the problem in iteration?
a.address!== null