JavaScript calculating length of a string
Why when I try this block of code:
var str = "1234";
alert(str.toString().lenght);
it alerts开发者_C百科 me 'undefined' ?
You misspelled length. It's "length":
str.toString().length
You don't actually need the toString() call here, though. "1234" is already a string, so str.length works as well.
correct your spelling...
alert(str.toString().lengTH);
Andrew
You have a spelling mistake in that code. It's length not lenght.
But aside from that, there's no need to call toString(). str.length is fine.
Just a typo: it's .length ;)
加载中,请稍侯......
精彩评论