Skip to content
Advertisement

Tag: trim

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 I am not sure how to solve this problem 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”)

Trim specific character from a string

What’s the JavaScript equivalent to this C# Method: C# trims the selected character only at the beginning and end of the string! Answer One line is enough: A general solution: Parameter c is expected to be a character (a string of length 1). As mentionned in the comments, it might be useful to support multiple characters, as it’s quite common

How to remove the extra spaces in a string?

What function will turn this contains spaces into this contains spaces using javascript? I’ve tried the following, using similar SO questions, but could not get this to work. Is there a simple pure javascript way to accomplish this? Answer You’re close. Remember that replace replaces the found text with the second argument. So: Finds any number of sequential spaces and

How to trim a string to N chars in Javascript?

How can I, using Javascript, make a function that will trim string passed as argument, to a specified length, also passed as argument. For example: Anyone got ideas? I’ve heard something about using substring, but didn’t quite understand. Answer Why not just use substring… string.substring(0, 7); The first argument (0) is the starting point. The second argument (7) is the

Advertisement