I'm trying to remove the first 13 characters of a string with this code:
requestToken = requestToken.substring(13);
However, I'm getting "has no method substring
" error with NodeJS, the code above that mostly recommended in the Javascript forums does not work with NodeJS?
it seems like requestToken may not be a string.
Try
requestToken = '' + requestToken;
and then requestToken.substring(13);
substring
(and substr
) are definitely functions on the string prototype in node; it sounds like you're not dealing with a string
$ node
> "asdf".substring(0,2)
'as'
Convert requestToken
to a string first:
requestToken = (requestToken+"").slice(13);
requestToken
must not be a string then. It's likely some sort of object, and the string you want is likely returned by a method on, or a property of, that object. Try console.log(requestToken)
and see what that really is.
You also want .slice()
for removing the front of a string.
And you will likely end up with something like:
myString = requestToken.someProperty.slice(13);
Coercing it to a string may not solve your problem. console.log(typeof(requestToken)) might give you a clue to what's wrong.
Try to check your object/variable:
console.log( JSON.stringify(yourObject) );
or it's type by
console.log( typeof yourVariable );