I am trying to remove the first 13 characters of a string using this code:
requestToken = requestToken.substring(13);
However, I get an error " has no method substring" with NodeJS, the code above, which is mostly recommended in Javascript forums, doesn’t work with NodeJS?
has no method substring
it looks like requestToken cannot be a string.
Try
requestToken = '' + requestToken;
and then requestToken.substring (13);
substring(i substr) are definitely string prototype functions in node; it looks like you are not dealing with a string
substring
substr
$ node > "asdf".substring(0,2) 'as'
requestToken :
requestToken
requestToken = (requestToken+"").slice(13);
requestToken . , - , , , on . console.log(requestToken) , .
console.log(requestToken)
You also want to .slice()remove the front of the line.
.slice()
And you will most likely get something like:
myString = requestToken.someProperty.slice(13);
Forcing a string may not solve your problem. console.log (typeof (requestToken)) can give you the key to what's wrong.
Try checking your object / variable:
console.log( JSON.stringify(yourObject) );
or enter it
console.log( typeof yourVariable );
requestToken.toString().slice(13);
or
if(typeof requestToken!="string") { requestToken.toString().slice(13); }else { requestToken.slice(13); }