1let person = {
2 firstname: 'John',
3 lastname: 'Doe'
4}
5
6console.log(person.firstname);
7// expected output: "John"
8
9delete person.firstname;
10
11console.log(person.firstname);
12// expected output: undefined
1// delete an element from the dom
2var elem = document.querySelector('#some-element');
3elem.parentNode.removeChild(elem);
4
5
6// keep element in dom
7var elem = document.querySelector('#some-element');
8elem.style.display = 'none';
1var ourDog = {
2 "name": "Camper",
3 "legs": 4,
4 "tails": 1,
5 "friends": ["everything!"],
6 "bark": "bow-wow"
7};
8
9delete ourDog.bark;
1// JavaScript "delete"
2const Employee = {
3 firstname: 'John',
4 lastname: 'Doe'
5};
6
7console.log(Employee.firstname);
8// expected output: "John"
9
10delete Employee.firstname;
11
12console.log(Employee.firstname);
13// expected output: undefined
14
15
16// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
1let monTableauAssociatif = {
2 'prenom' : 'Mark' ,
3 'nom' : 'Zuckerberg' ,
4 'poste' : 'Pdg de Facebook',
5
6 } ;
7 delete(monTableauAssociatif.poste)
8 console.log(monTableauAssociatif) ;
9