Javascript String Processing (NodeJS)

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?

+3
source share
7 answers

it looks like requestToken cannot be a string.

Try

requestToken = '' + requestToken;

and then requestToken.substring (13);

+7
source

substring(i substr) are definitely string prototype functions in node; it looks like you are not dealing with a string

$ node
> "asdf".substring(0,2)
'as'
+4
source

requestToken :

requestToken = (requestToken+"").slice(13);
+2

requestToken . , - , , , on . console.log(requestToken) , .

You also want to .slice()remove the front of the line.

And you will most likely get something like:

myString = requestToken.someProperty.slice(13);
+1
source

Forcing a string may not solve your problem. console.log (typeof (requestToken)) can give you the key to what's wrong.

0
source

Try checking your object / variable:

console.log( JSON.stringify(yourObject) );

or enter it

console.log( typeof yourVariable );
0
source
requestToken.toString().slice(13);

or

if(typeof requestToken!="string")
{
   requestToken.toString().slice(13);
}else
{
   requestToken.slice(13);
}
0
source