Skip to main content
Version: Next

objectIsDefined

objectIsDefined ( object : object {, property : string } ) : boolean

ParameterTypeDescription
objectobjectObject to work with
propertystringIf passed = property to check, if omitted = check object
Resultboolean
  • If property omitted: true if object is defined, otherwise false.
  • If property passed: true if property is defined, otherwise false.
  • Description

    The objectIsDefined command returns true if object or property is defined, and false otherwise.

    By default, if you omit the property parameter, the command checks whether the object is defined. An object is defined if its contents has been initialized.

    note

    An object can be defined but empty. To find out if an object is undefined or empty, use the objectIsEmpty command.

    If you pass the property parameter, the command checks whether this property exists in object. Note that the property parameter is case sensitive. If the property is not found at the first level of object, the command does nothing.

    Example 1

     var obj : object
    var def : boolean
    def = objectIsDefined(obj) //false, obj is not initialized

    obj = newObject("Name","Martin")
    objectRemove(obj, "Name")
    def = objectIsDefined(obj) //true, obj is empty but initialized

    Example 2

     var obj : object

    obj = newObject("Name","Smith", "Age", 42)
    ...
    if(objectIsDefined(obj,"Age")
    ...
    end

    This test is equivalent to:

     if(valueType(obj,"Age") != Is undefined)

    See also

    objectIsEmpty