The removeAll() method removes all key-value pairs from the dictionary.
Example
removeAll() Syntax
The syntax of the removeAll() method is:
dictionary.removeAll()
Here, dictionary is an object of the Dictionary class.
removeAll() Parameters
The removeAll() method doesn't take any parameter.
removeAll() Return Value
- The
removeAll()method doesn't return any value. It only removes key-value pairs from the dictionary.
Example: Swift removeAll()
Output
Before: ["Two": 2, "one": 1, "Three": 3] After: [:]
In the above example, we have created a dictionary named numbers with three key-value pairs.
Here, we have used the removeAll() method to remove all key-value pairs from numbers.