get
Modified on Tue, 05 Sep 2023
Description
Use this function to get the value at a specified path of an object. If the resolved value is 'undefined', the provided 'defaultValue' is returned in its place.
Syntax
get(object: PropertyPath, path, defaultValue)
Returns
Return Value | Description |
---|---|
Value | Returns the resulting value obtained from the specified path in the object. If the resolved value is 'undefined', the 'defaultValue' is returned instead. |
Sample
Example | Result | Description |
---|---|---|
get({ name: 'John', age: 30 }, 'name', 'Default') | 'John' | Returns 'John' because the 'name' property exists in the object. |
get({ name: 'John', age: 30 }, 'city', 'Default') | 'Default' | Returns 'Default' because the 'city' property does not exist in the object and the default value is provided. |
Additional Example
To retrieve the "SelfEmpID" attribute from a Business Object (BO) depending on its structure:
If the BO is structured:
get(employeeInformation, "SelfEmpID")
If the BO is a list type and you want to get the attribute from the first element:
get(nth(employeeInformation, 0), "SelfEmpID")
OR
get(employeeInformation[0], "SelfEmpID")
Assuming the attribute name is: "SelfEmpID."
To view all Object functions, click here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article