Returns true if the input collection (array or object) has no elements or properties.
Check for empty arrays and objects
{{hasNoItems record.arr1}}
{{hasNoItems record.arr2}}
{{hasNoItems record.obj1}}
{{hasNoItems record.obj2}}
Input:
{
"record": {
"arr1": [],
"arr2": [1, 2],
"obj1": {},
"obj2": { "x": 1 }
}
}
Output:
true false true false
Conditional rendering example
{{#if (hasNoItems record.items)}}
No items found
{{else}}
Items present
{{/if}}
Input:
{ "record": { "items": [] } }
Output:
No items found
Tip
-
Works for both arrays and plain objects.
-
Returns
trueonly when there are no elements (for arrays) or no keys (for objects). -
Use with
#ifor#unlessfor conditional logic when checking for empty collections.