Saturday 22 April 2017

Node.js: Unable to use trim() on string

I have an array of strings read from an Excel sheet in Node.js.

for(var i = 0; i < data.length; i++) {
    var value = data[i];        
    console.log(typeof value); 
}

This prints string for all elements. However, value.trim() returns the following error: TypeError: value.trim is not a function. To make it work, I had to do the following: value.toString().trim(). Does this behaviour have an explanation?



via raul

No comments:

Post a Comment