The delete
operator is used to remove a property from a JavaScript object. It returns true
if the property is removed successfully, otherwise false
.
const fruits = {
orange: '🍊',
lemon: '🍋',
kiwi: '🥝',
mango: '🥭'
}
delete fruits.kiwi
// OR
delete fruits['kiwi']
console.log(fruits)
// { orange: '🍊', lemon: '🍋', mango: '🥭' }
The delete
operator works with both dot notation (.
) and square bracket ([]
) notation.