Reflect.deleteProperty()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.

La méthode statique Reflect.deleteProperty() permet de supprimer des propriétés. Il agit comme l'opérateur delete.

Exemple interactif

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

js
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.

Valeur de retour

Un booléen qui indique si la suppression de la propriété s'est bien passée.

Exceptions

Une erreur TypeError si cible n'est pas un Object.

Description

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.

Exemples

js
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

Specification
ECMAScript® 2025 Language Specification
# sec-reflect.deleteproperty

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
deleteProperty

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi