Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Why when I try this block of code:
var str = "1234"; alert(str.toString().lenght);
it alerts me 'undefined' ?
You misspelled length. It's "length":
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.
toString()
"1234"
str.length
Add a comment
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 ;)
.length
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.