Function aryval

  • get value of array by key name list

    Parameters

    • valIn: any

      array of associative array

    • sKey: string

      concatinated key list with dot (ex. 'type.name.0.info')

    • Optional defIn: any

      default value if value is not found (OPTIONAL)

    Returns any

    value if found otherwise returns def

    Description

    This function returns the value of an array or associative array which referred by a concatinated key list string. If a value for key is not defined, it returns 'undefined' by default. When an optional argument 'def' is specified and a value for key is not defined, it returns a value of 'def'.

    Example

    let p = {
    fruit: apple,
    info: [
    { toy: 4 },
    { pen: 6 }
    ]
    };
    aryval(p, 'fruit') -> "apple"
    aryval(p, 'info') -> [{toy: 4},{pen: 6}]
    aryval(p, 'info.1') -> {pen: 6}
    aryval(p, 'info.1.pen') -> 6
    aryval(p, 'money.amount') -> undefined
    aryval(p, 'money.amount', null) -> null