I have a really weird number in my mongoDB document. I copied the whole object over to the node console. I’m outputting it here. I’m thinking it has a combination of string \n‘s and actual textual \n‘s or something weird going on. Can someone tell me how to just get the number 567899876545678987654 as a string, out of the variable below?
> number
'--- \n- "567899876545678987654"\n- \n'
> JSON.stringify(number);
'"--- \\n- \\"567899876545678987654\\"\\n- \\n"'
> number.replace("\n","");
'--- - "567899876545678987654"\n- \n'
> number.replace(/\n/,"");
'--- - "567899876545678987654"\n- \n'
> number.replace(/-/,"");
'-- \n- "567899876545678987654"\n- \n'
Why not use a regex for all digits instead of trying to remove the rest?
As T.J. Crowder points out,
actualNumberwill now be an array containing the number (if there was one). As he suggests, this will safely retrieve the actual number: