Results 1 to 5 of 5

Thread: external js array

  1. #1
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default external js array

    if i have an array in an external js file such as:

    var blah = new Array();
    blah[0] = "sumthing";
    blah[1] = "...";
    blah[2] = "=D";

    how would i create a document that displays the array?

  2. #2
    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

    Code:
    document.write(blah.toString())
    - John
    ________________________

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

  3. #3
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanx a lot ^^

  4. #4
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry but another question on arrays...just say my array was:
    var answer = new Array();
    answer[0] = "yes";
    answer[1] = "no";
    answer[2] = "maybe";
    answer[3] = "yes";
    answer[4] = "yes";

    how would i display only the values that are "yes"?

  5. #5
    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

    This is sort of silly because there are many ways to do this and I have no idea why you are doing it. That would influence my choice of methods. This is one way:
    Code:
    var str=''
    for (var i_tem = 0; i_tem < answer.length; i_tem++)
    if ( answer[i_tem]=='yes' )
    str += answer[i_tem]+' '
    document.write(str)
    - 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
  •