Skip to content

Set ​

Métodos y propiedades nativos ​

MiembroFirmaComportamiento
sizeusizeCantidad de valores distintos.
addadd(value: T): Set<T>Inserta un valor si todavía no existe y devuelve el set.
hashas(value: T): booleanComprueba si un valor está presente.
deletedelete(value: T): booleanElimina un valor e indica si estaba presente.
valuesvalues(): T[]Devuelve los valores actuales como un array.

También se puede recorrer un set directamente con for...of. Añadir un valor existente no crea un duplicado.

tyrus
const uniqueTags: Set<string> = Set(["rust", "native", "rust"]);
uniqueTags.add("fast");                      // Set { "rust", "native", "fast" }
const hasNative: boolean = uniqueTags.has("native"); // true
uniqueTags.delete("fast");                   // Set { "rust", "native" }
const count: usize = uniqueTags.size;        // 2

for (const tag of uniqueTags) {
    print(tag); // "rust", "native"
}