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 :: javascript split multiple values 
Javascript :: npx vs npm 
Javascript :: react children length 
Javascript :: require vs import 
Javascript :: how to select last element in a array 
Javascript :: update a value from array in redux state 
Javascript :: js add event listener 
Javascript :: set get variable in url 
Javascript :: airbnb react native eslint 
Javascript :: remove node from linked list c 
Javascript :: react native svg size 
Javascript :: map values js 
Javascript :: vanilla tilt js 
Javascript :: javascript advanced interview questions 
Javascript :: autocomplete html in react 
Javascript :: redirect to another path react 
Javascript :: angular auth guard 
Javascript :: prisma database example 
Javascript :: Iterating or loop through the elements of an array is with a for loop (for): 
Javascript :: method function difference 
Javascript :: print console.log 
Javascript :: ant design form validation in the modal 
Javascript :: call function 
Javascript :: how to create a variable in javascript 
Javascript :: js filter array 
Javascript :: react native splash screen 
Javascript :: TypeError: Converting circular structure to JSON 
Javascript :: react-dropzone-uploader 
Javascript :: javascript algorithm interview questions 
Javascript :: discord.js vs discord.py 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =