Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js weakset

const ws = new WeakSet();
const foo = {};
const bar = {};

ws.add(foo);
ws.add(bar);

ws.has(foo);    // true
ws.has(bar);    // true

ws.delete(foo); // removes foo from the set
ws.has(foo);    // false, foo has been removed
ws.has(bar);    // true, bar is retained
Comment

javascript WeakSet Methods

const weakSet = new WeakSet();
console.log(weakSet); // WeakSet {}

const obj = {a:1};

// add to a weakSet
weakSet.add(obj);
console.log(weakSet); // WeakSet {{a: 1}}

// check if an element is in Set
console.log(weakSet.has(obj)); // true

// delete elements
weakSet.delete(obj);
console.log(weakSet); // WeakSet {}
Comment

JavaScript WeakSet

const weakSet = new WeakSet();
console.log(weakSet); // WeakSet {}

let obj = {
    message: 'Hi',
    sendMessage: true
}

// adding object (element) to WeakSet
weakSet.add(obj);

console.log(weakSet); // WeakSet {{message: "Hi", sendMessage: true}}
Comment

PREVIOUS NEXT
Code Example
Javascript :: code challenges javascript 
Javascript :: open new window chrome extension 
Javascript :: get dir from filepath javascript 
Javascript :: select element as role in jquery 
Javascript :: how to create immutable object in javascript 
Javascript :: js concat variable and string 
Javascript :: js set css variable 
Javascript :: jquery match height,jquery matchheight 
Javascript :: 150 pound in kg 
Javascript :: miles to metres 
Javascript :: remove comma from number javascript 
Javascript :: javascript disable form 
Javascript :: javascript if a variable is undefined 
Javascript :: remove special characters from string 
Javascript :: n javascript 
Javascript :: toggle hook react 
Javascript :: dynamic folder import javascript 
Javascript :: jquery in array 
Javascript :: user focus on tab javascript 
Javascript :: javascript compare arrays 
Javascript :: jquery table each rows with class 
Javascript :: mongoose schema cast decimals 
Javascript :: firebase for vue project 
Javascript :: jwt token expire time in node js 
Javascript :: showing bootstrap modal after a delay 
Javascript :: nuxt axios middleware 
Javascript :: return symmetric difference of the array javascript 
Javascript :: Too long with no output (exceeded 10m0s): context deadline exceeded 
Javascript :: using dto in express 
Javascript :: add attribute in select option 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =