Skip to content
Advertisement

Nodejs trim() is not a function

I get this error when I run and can not seem to resolve it.

TypeError: data[key].trim is not a function

The function is this one

JavaScript

I am not sure how to solve this problem

Advertisement

Answer

I think there is a possibility what data[key] isn’t a string type.

try this:

Change if(data[key] !== "") to if(typeof data[key] === "string")

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement