Skip to content

Instantly share code, notes, and snippets.

@rsolomo
Created July 31, 2013 23:45
Show Gist options
  • Save rsolomo/6127270 to your computer and use it in GitHub Desktop.
Save rsolomo/6127270 to your computer and use it in GitHub Desktop.
strings only set example
// ECMA 5
var duplicates = ['taco', 'taco', 'bacon', 'pancake', 'cake', 'salt', 'cake']
var set = {}
duplicates.forEach(function(value) {
set[value] = true
})
console.log(Object.keys(set)) // Outputs an array with no duplicates
// Check for prescence of a value
console.log('waffles' in set) // false
// Remove value from set
console.log('taco' in set) // true
delete set.taco
console.log('taco' in set) // false
// Iterate over set
Object.keys(set).forEach(function(value) {
// Do stuff
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment