Get String Length with Javascript
To get string length with Javascript:
ko="I will count this string now!";
ji=ko.length;
document.write(ji);
Which Prints:
29
-We create a variable and named it
ko because we like short names.
-We created a new variable and named it
ji.
-We used Javascript's built-in
length method on
ko and stored it's value in
ji.
-We printed to the brower using Javascript's
document.write.
If you wanted to be showy, you could shorten this code like so:
ji="I will count this string now!" .length;
document.write(ji);
Which Prints:
29
-Here, we just applied Javascript's built-in
length method directly to the string we wanted a count on.
-Stored it in
ji and printed.
Free Copy and Paste Javascript Code:
<script type="text/javascript">
<!--
ko="I will count this string now!";
ji=ko.length;
document.write(ji);
ji="NO, I will count THIS string now!" .length;
document.write(ji);
-->
</script>
Resources:
www.quirksmode.org - Great Resource on Strings and Javascript
PRINT to Browser with document.write Command in Javascript
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
CSS David McFarland | | |
| | | |
| | | |