I have class in Angular 6
export class classXY{
xValue: number;
yValue: number;
xDate: Date;
yDate: Date;
xName?: string;
yName?: string;
}
in my code, I need to check the properties that have type number.
let obj: ClassXY;
obj.xValue=1;
obj.yValue=null;
obj.xDate= new Date();
obj.yDate= null;
obj.xName= "test";
obj.yName= null;
for (var key in obj) {
if ((obj[key] == null) && (typeof obj[key] === "number"))
obj[key] = -1;
}
typeof obj["yValue"] value is null and typeof "yValue" is string, while I need to return the type of property number. Same for instanceof
How I check the primitive type of property of an object?