Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    89
    Thanks
    51
    Thanked 0 Times in 0 Posts

    Objects question

    Hi

    Dumb question, but I can't figure this simple thing out...

    I have an array of objects:
    Code:
    var monthlyDP:Array = new Array({label:"1st", X:"first"},{label:"2nd", X:"second"},{label:"3rd", X:"third"},{label:"4th", X:"fourth"},{label:"last", X:"last"});
    I know "1st", and want to retrieve the value associated with it (so "first").

    Is it a case of having to also know the index of that object, or is there a way to seach and array like this when you know the label of the object, and just want the value?

    Thanks!

  • #2
    New Coder
    Join Date
    Jan 2012
    Location
    Columbus, Ohio, U.S.A
    Posts
    41
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Hi there,

    I'm hoping I understand your question right but I'll try:

    would it be possible for you to use a dictionary for this? (associative array, same thing)

    and say something like:
    PHP Code:
    var monthlyDP:Dictionary = new Dictionary();
    monthlyDP["1st"] = "first";
    monthlyDP["2nd"] = "second";
    monthlyDP["3rd"] = "third"
    ...and so on.

    that way you get direct access. Of course there are multiple ways of doing this.

    Hope that starts you in the right direction.

    -Adam

  • Users who have thanked adaminaudio for this post:

    shaunthomson (01-04-2013)

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    89
    Thanks
    51
    Thanked 0 Times in 0 Posts
    THAT would be SOOOOOOO much easier. I'm going to try it. Thank you!


  •  

    Posting Permissions

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