Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    How to check if an array key exists

    If I use a variable argument list is there a way to check how many of the variable arguments are set. For example:

    public Object method Name(Object req_input, Object... add_inp)

    I would like to know if add_input[0] is set, and also the number of add_inp[] entries that are set. Thanks.
    Last edited by Fou-Lu; 06-21-2012 at 06:59 PM.

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    Its an array. Use add_inp.length to determine if an offset is available (length is size + 1, so if its 0, you have no data). Try/catch can be used as well, but I would recommend using an if check instead.


Posting Permissions

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