Reputation: 89
Why when I try this block of code:
var str = "1234";
alert(str.toString().lenght);
it alerts me 'undefined' ?
Upvotes: 1
Views: 1151
Reputation: 15952
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.
Upvotes: 1
Reputation: 4578
correct your spelling...
alert(str.toString().lengTH);
Andrew
Upvotes: 1
Reputation: 48596
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.
Upvotes: 7