A set is a data structure to store unique values that must not have duplicates. With the delete()
method, we can delete an entry from a set.
set.delete(value)
set
: This is the set from which we want to delete an entry.
value
: This is the value we want to delete from the set.
If the entry is found and successfully deleted, then true
is returned. Otherwise, false
is returned.
// create some setslet names = new Set<string>(["Theodore", "David", "John", "Janme"])let evenNumbers = new Set<number>([2, 4, 6, 8, 10, 12])let booleanValues = new Set<boolean>([true, false])let countries = new Set<string>(["Nigeria", "Brazil", "Ghana", "Egypt", "Germany"])// check if they contain some valuesconsole.log(names.delete("Theodore")) // trueconsole.log(evenNumbers.delete(5)) // falseconsole.log(booleanValues.delete(true)) // trueconsole.log(countries.delete("Tokyo")) // false// log out the setsconsole.log(names)console.log(evenNumbers)console.log(booleanValues)console.log(countries)
delete()
method to delete some entries of the sets we created. Then, we log out the returned result to the console.