dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: complex if statement, check number with array

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    211

    complex if statement, check number with array

    Is there a way to check to see if one number matches any number in an array without looping through the array in a for loop?

    for example

    instead of
    Code:
    for(i=0; i<myArray.length, i++)
    {
    if(a == myArray[i]){//doThis}else{}
    }
    maybe do something like this
    if(a == myArray){doThis}

    although this doesn't work, is there a syntax that allows for this?
    -FRIG-5
    Das Konzept Design
    www.daskonzept.com

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    what are u trying to do? why dont u want to loop through the array to see if there is a match?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    211
    well, I don't have a problem with looping through an array, I was just wondering if someone knew about a less code-heavy way to do it.
    -FRIG-5
    Das Konzept Design
    www.daskonzept.com

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    well one option is to use an associative array ( although this wont be convenient in most cases) instead of an indexed array

    e.g

    Code:
    var aNames:Array = [];
    
    aNames["john"] = "john";
    aNames["pat"] = "pat";
    aNames["pam"] = "pam";
    
    //then to check if pam exists in the array you would do
    
    if(aNames["pam"] != undefined){
    trace("pam exists");
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center