I'm trying to create a new object that contains all of the key/value pairs from an object where the values are null. Here is the code thus far -
const d = { pp: 1700, no: 2300, co: null, ng: 4550, zx: null };
const nulls = {};
Object.entries(d).forEach(([k, v]) => v === null ? nulls[k]: v);
console.log(nulls);
The desired outcome is that the nulls
object contains { co: null, zx: null }
; however, the code above causes nulls
to be an empty object.
What needs to be modified to get the necessary output? Maybe there is a more concise approach...possibly using .filter()
?