Delete/Drop a key-value pair from an object
In Javascript, if you want to drop or delete a key-value pair from an object you just pass the object.key to the delete keyword, like this:
// Assume we have an object like this
let object = {
toyota: ['camry'],
honda: ['accord', 'civic']
}
// It would display something like this
object
=> {toyota: ['camry'], honda: ['accord', 'civic'] }
// We can drop/delete the object value like this
delete object.toyota
=> true
// It would now display something like this
object
=> {honda: ['accord', 'civic']}
Tweet