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 :: loop array in javascript 
Javascript :: js input type range on hover 
Javascript :: using iframe in chrome console 
Javascript :: how to detect a url change 
Javascript :: disable scroll on modal open 
Javascript :: tailwind hover dont work 
Javascript :: momentTimeZone 
Javascript :: nested for loop javascript 
Javascript :: How to call a c# functio from Javascript 
Javascript :: how to disable onclick event in javascript 
Javascript :: nodejs aws s3 bucket delete item 
Javascript :: how to add two attay into object in javascript 
Javascript :: multiple line string in jquery 
Javascript :: how to capitalize first letter javascript 
Javascript :: react native text capitalize 
Javascript :: how can i validate a password without regex in js 
Javascript :: viewchild for ngfor 
Javascript :: sls invoke local 
Javascript :: select2 clear fields 
Javascript :: javascript change background color 
Javascript :: check if string contains substring javascript 
Javascript :: Could not find the drag and drop manager in the context of ResourceEvents. Make sure to wrap the top-level component of your app with DragDropContext app.js 
Javascript :: tailwind config 
Javascript :: download json file from s3 
Javascript :: js markdown to html 
Javascript :: chartjs line color 
Javascript :: add event listener in react useeffect 
Javascript :: chrome.tab.onupdated 
Javascript :: substring javascript 
Javascript :: first letter of each word in a sentence to uppercase javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =