Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

hashset in javascript

let mySet = new Set()

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

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

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

mySet.size         // 5

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

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

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

PREVIOUS NEXT
Code Example
Javascript :: set lodash 
Javascript :: how to use js console log 
Javascript :: process.argv 
Javascript :: jquery loop 0 to 10 
Javascript :: data-dismiss="modal" in js 
Javascript :: match city regex 
Javascript :: round to decimal javascript 
Javascript :: change a variable outside a function js 
Javascript :: nodejs download file 
Javascript :: sort array of objects javascript by key value 
Javascript :: reverse the string in javascript 
Javascript :: how to connect mysql using node js stack 
Javascript :: js catch rejected promise 
Javascript :: Which react-bootstrap component you will use for width: 100% across all viewport and device sizes 
Javascript :: preview image before upload reactjs 
Javascript :: js select last item in html list query selector 
Javascript :: pass variable to partial view ejs 
Javascript :: how to auto refresh page in javascript 
Javascript :: javascript online test 
Javascript :: next.js index page 
Javascript :: get data from url using react 
Javascript :: bodyparser express deprecated 
Javascript :: repeat a function javascript 
Javascript :: js get integer value of 
Javascript :: for javascript 
Javascript :: javascript get width 
Javascript :: moment set time 
Javascript :: react tabs 
Javascript :: vue change specific params/query 
Javascript :: react native navigation shared element 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =