开发者

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 ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜