The hasOwn helper checks whether the specified key is an own, enumerable property of the given object. It returns true if the property exists directly on the object (not inherited).
{{hasOwn object "key"}}
-
object (required): The context object to check
-
key (required): The property name to test (string)
Check for existing and missing properties
{{hasOwn record.config "theme"}}
{{hasOwn record.config "version"}}
Input:
{
"record": {
"config": {
"theme": "dark",
"debug": true
}
}
}
Output:
true false
Conditional usage
{{#if (hasOwn record.config "debug")}}
Debug mode enabled
{{else}}
Debug property not found
{{/if}}
Input:
{
"record": {
"config": {
"theme": "light",
"debug": true
}
}
}
Output:
Debug mode enabled
Tip
-
Works only for own properties, not those inherited through prototypes.
-
Ideal for verifying optional settings or configuration fields in objects.
-
Use with
#ifor#unlessto conditionally render sections based on property existence.