Set.prototype.clear()

Baseline Widely available

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

La méthode clear() permet de retirer tous les éléments d'un ensemble Set.

Exemple interactif

Syntaxe

js
monSet.clear();

Valeur de retour

Exemples

js
var monSet = new Set();
monSet.add(1);
monSet.add("toto");

monSet.size; // 2
monSet.has("toto"); // true

monSet.clear();

monSet.size; // 0
monSet.has("truc"); // false

Spécifications

Specification
ECMAScript Language Specification
# sec-set.prototype.clear

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi