I've read the answers to this question why is typeof null "object"? and I'm trying to figure out a solution to a specific problem.
I am working on a Web application with angularJs for the front-end and ASP.NET MVC for the server code. We're passing our models to the front-end and then updated values back. Here is the situation I'm trying to find a solution for:
When we're deleting numbers from the input type="number" using a backspace key in the Web interface, the value of the input control becomes null. In our models the numeric values are defined as not nullable (and in our database the strings also should be converted to empty values instead of null).
I am trying to figure out a way to set keys to 0 if they are numeric and to empty string if they are strings.
I've added a new method called verifyInput and here is the beginning of the code:
/**
* @returns true or false
* */
Model.prototype.verifyInput = function () {
for (let i = 0; i < this.keys.length; i++) {
const key = this.keys[i];
if (this[key] === null) {
this[key] =
}
}
}
I am not sure how to write the above method. I already found out that I can not use typeof or lodash methods to check for key's type as it's returning object. I need to set numbers to 0 and strings to empty strings, but leave datetime values alone. Do you see my problem and do you have ideas of a solution? Perhaps I should use try/catch here?