Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

es6 hashset

const mySet1 = new Set()

mySet1.add(1)           // Set [ 1 ]
mySet1.add(5)           // Set [ 1, 5 ]
mySet1.add(5)           // Set [ 1, 5 ]
mySet1.add('some text') // Set [ 1, 5, 'some text' ]
const o = {a: 1, b: 2}
mySet1.add(o)

mySet1.add({a: 1, b: 2})   // o is referencing a different object, so this is okay

mySet1.has(1)              // true
mySet1.has(3)              // false, since 3 has not been added to the set
mySet1.has(5)              // true
mySet1.has(Math.sqrt(25))  // true
mySet1.has('Some Text'.toLowerCase()) // true
mySet1.has(o)       // true

mySet1.size         // 5

mySet1.delete(5)    // removes 5 from the set
mySet1.has(5)       // false, 5 has been removed

mySet1.size         // 4, since we just removed one value

console.log(mySet1)
// logs Set(4) [ 1, "some text", {…}, {…} ] in Firefox
// logs Set(4) { 1, "some text", {…}, {…} } in Chrome
Comment

PREVIOUS NEXT
Code Example
Javascript :: js parse bool 
Javascript :: date range picker in angular 8 
Javascript :: save image on cloudinary 
Javascript :: javascript shell 
Javascript :: double click react 
Javascript :: check if string contains a value in array 
Javascript :: how to identify debug and release build in react native 
Javascript :: react-validex 
Javascript :: days.js 
Javascript :: update TextInput value react-hook-form react-admin 
Javascript :: how to name a file path in document.geteleementbyid 
Javascript :: jquery show hide animation slide 
Javascript :: variavel javascript 
Javascript :: Generate random phone numbers in POSTMAN 
Javascript :: mouse wheel scroll sections in react 
Javascript :: Create a Simple Delay Using setTimeout 
Javascript :: javascript class in external file 
Javascript :: how to print the error massege in js 
Javascript :: how to create a search engine with javascript 
Javascript :: public JsonResult what is the return 
Javascript :: loop number in react 
Python :: minecraft 
Python :: sqlalchemy python install 
Python :: how to install OpenCV? 
Python :: check python 32 or 64 
Python :: get ip from instance id boto3 
Python :: pip clear cache command 
Python :: selenium python find all links 
Python :: How to play music without pygame 
Python :: import apiview 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =