Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: The .length thing in Javascript

  1. #1
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation The .length thing in Javascript

    Well hello,

    I have seen a few properties in my time for javascript which i do not completely understand how to use, in this case it would be .length.

    On the web I have seen this property being used to disply animated text which goes up by one (an example can be found at http://www.w3schools.com/dhtml/tryit...tml_typewriter)

    Well so can anyone explain how to properly use .length - and it's uses.

    Thanks

  2. #2
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It gives you the number of elements in an array, or the number of characters in a string.

    If x is a string or array, x.length will give you its length.
    Last edited by Blake; 02-26-2007 at 01:59 AM.
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  3. #3
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yup, the basics -

    I have been through them before and I have seen some great animations with use of that, any idea on how to do them or any intermediate examples

    By the way GREAT MILITARY SITE !!!! ROCK ON !!!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's quite rare to see a green-on-black design carried out in such a way that it doesn't look like it's been designed by some script kiddy who's spent way too long watching Matrix reruns. Congratulations.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Uhhh, the thing is the reason that the page doesn't look like it was created by a script kiddy is because it wasn't, it was created by a script adulty

    So getting back to .length

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well, the length property has been explained. There's not really much more to it.
    the reason that the page doesn't look like it was created by a script kiddy is because it wasn't, it was created by a script adulty
    It's still rather difficult to produce a green-on-black page that looks decent. Try it some time.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No no no no, you got it all wrong I was just joking about the green black thing

    But about the length thing is that i have seen certain animation that use the .length property but i simply do not understand what the .length part does as it's job...

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    maxlength=message.length+1
    Set maxlength to be equal to the length of the message plus one.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yah that's it !!!
    But may I have a VERY VERY simple animation script wriiten by you to study ?
    But not to advanced I will simply work on yours until I understand it and make my own from there

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The length property is so simple, it can be hard to understand it at first, especially if you are looking for some deep meaning. It has no deep or even complex meaning. Here is a string:

    Code:
    "I'm a string"
    It has 12 characters (including spaces and punctuation). It's length is 12. Try this:

    Code:
    <script type="text/javascript">
    alert ("I'm a string".length)
    </script>
    Length can apply to other things besides strings. For the most part it is only used with strings and arrays. Here is an array:

    Code:
    ["I'm", "an", "array"]
    It has three items. Its length is three:

    Code:
    <script type="text/javascript">
    alert (["I'm", "an", "array"].length)
    </script>
    The length property is used in javascript to determine how long things are so other operations can be carried out - say once for each unit of length, or on/for each item that represents a unit of length. It's that simple.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •