Object.get
Object.get
Function
Read the specified key of the object and return the default value if missing.
Syntax
object.get(key, default_value)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| key | String | Yes | None | The key to read. |
| default_value | Any | No | empty | The default value returned when the key does not exist. |
Return value
| Type | Description |
|---|---|
| Any | The value of the corresponding key, or the default value. |
Code Example
user = {name: 'BT'} result = user.get('age', 1) // Output: 1 print result
Notes
- If the field exists and the value is null, null is returned and the default value is not used.