SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: String array...

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question String array...

    hi ....
    i'm a rookie on java so i'd apreciate some help on this...
    i want a function that does something like this
    load_strings("str1","str2","str3", ...}
    no specific number of strings
    giving me an array with a relative number of items...

    if this can be done, how do i know how many items the array has??

    thanks...

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    It's called the Array constructor:
    Code:
    var myArray = new Array("what", "do", "you", "want", "with", "those", "fries");
    And to get the count of items in an array, use the length property:
    Code:
    var arrayLen = myArray.length;

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... and how can i use the array constructor in the html??

    <html><head>
    <script language="javascript">

    function load_strings(???){
    // get array lenght??

    }
    </script>
    </head><body>

    <input type="button" onClick="load_strings('what','efsertf','dszfs',...)">

    having the function with no specicif number of arguments...
    meaning with this, that i can load an array of 3 or 4 ... elements...

    the number of items in the array isn't defined...

    if it is possible...

    thanks vgarcia


  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Why do you need a function for that? If you want one, you can do this:
    Code:
    function load_strings()
    {
      return arguments;
    }
    In any function, "arguments" is an array of all the arguments passed to the function. So using my function above, you can do something like this:
    Code:
    var whatever = load_strings('what', 'blah', 'hay', 'this');
    alert(whatever.length);
    I still don't see what the point of creating a function is if you can just create an array instead.

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    want i want in the java function is this array:
    ('what', 'blah', 'hay', 'this');
    , but i want to define the strings, and number the of strings that it has, in the html, not inside the javascript.


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
  •