Created
July 31, 2013 23:45
-
-
Save rsolomo/6127270 to your computer and use it in GitHub Desktop.
strings only set example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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