r/javascript•
Calculusbitch

Trying to convert object to string, the new variable just contains [object text]

So I have a textnode that contains some text as an object text. I am supposed to count the amount of characters and that is no problem with .length(). The problem starts when I want to remove some characters, for this I use .replace() but for that I need to convert the object to a string. When I do this the variable just becomes [object text]. This piece of code returns that n contains 13 character regardless of what I write. If I dont try to convert it to a string it works correct. am I trying to convert it wrong or what is going on?

var count = 0

var str = String(textnode)

n=n.replace(/., " "/g,"");	


count = str.length;


return count;

Posted Dec 2, 2012, 7:55 PM UTC

06
Loading comments…