.isEmpty
Anonymous contributor
Published Sep 25, 2023
Contribute to Docs
The .isEmpty
property returns true
if an array contains no elements, and returns false
if the array contains one or more elements.
Syntax
arrayName.isEmpty
Where arrayName
is the array being checked for elements.
Example
The following example creates and array and evaluates the contents of the array with .isEmpty
before and after adding an element:
var favoriteSongs = [String]()print(favoriteSongs.isEmpty)favoriteSongs.append("Stayin' Alive")print(favoriteSongs.isEmpty)
This will output:
truefalse
Note: Big-O of this method is O(1).
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.