Jump to content

is object empty?


Recommended Posts

Posted (edited)

 

On 4/16/2013 at 7:10 PM, iamtheky said:

The below works, but is there a better way to determine if the object is empty rather than counting elements?

I know it's an old thread, but it seems the focus was on a very specific object, so the general issue still remains unsolved.

I ask in general, where the keys are named dynamically so I can't test their existence, how to know if the object is empty i.e. the object has no keys?

The aforementioned loop is the only way I managed to find, but at least I've shortened it to just 1 iteration instead of an unneeded count:

Local $key, $found = False
For $key in $myObj
    $found = True
    ExitLoop
Next
If Not $found Then
    ConsoleWrite("Object is empty" & @CRLF)
EndIf

 

Edited by LWC
Used capital letters
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...