The isEmpty property checks if the array is empty or not.
Example
isEmpty Syntax
The syntax of the array isEmpty property is:
array.isEmpty
Here, array is an object of the Array class.
isEmpty Return Values
The isEmpty property returns:
- true - if the array does not contain any elements
- false - if the array contains some elements
Example 1: Swift Array isEmpty
Output
false true
In the above example, since
- names contain three string elements, the property returns
false. - employees is an empty array, the property returns
true.
Example 2: Using isEmpty With if...else
Output
Array is empty
Here, the names array is empty, so the if block is executed.