Baseline Widely available
La méthode statique Reflect.deleteProperty()
permet de supprimer des propriétés. Il agit comme l'opérateur delete
.
const object1 = {
property1: 42,
};
Reflect.deleteProperty(object1, "property1");
console.log(object1.property1);
// Expected output: undefined
const array1 = [1, 2, 3, 4, 5];
Reflect.deleteProperty(array1, "3");
console.log(array1);
// Expected output: Array [1, 2, 3, undefined, 5]
Syntaxe
Reflect.deleteProperty(cible, cléPropriété);
Paramètres
cible
L'objet cible sur lequel on souhaite supprimer la propriété.
cléPropriété
Le nom de la propriété à supprimer.
Un booléen qui indique si la suppression de la propriété s'est bien passée.
ExceptionsUne erreur TypeError
si cible
n'est pas un Object
.
La méthode Reflect.deleteProperty
permet de supprimer une propriété d'un objet. Elle renvoie un Boolean
qui indique si la propriété a été supprimée correctement. Cette méthode est très proche de l'opérateur delete
.
var obj = { x: 1, y: 2 };
Reflect.deleteProperty(obj, "x"); // true
obj; // { y: 2 }
var arr = [1, 2, 3, 4, 5];
Reflect.deleteProperty(arr, "3"); // true
arr; // [1, 2, 3, , 5]
// Renvoie true si aucune propriété correspondante n'existe
Reflect.deleteProperty({}, "toto"); // true
// Renvoie false si une propriété n'est pas configurable
Reflect.deleteProperty(Object.freeze({ toto: 1 }), "toto"); // false
Spécifications Compatibilité des navigateurs Voir aussi
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4