Created
May 17, 2016 22:55
-
-
Save joates/1a03072904552f0b1499fc6db896f7b2 to your computer and use it in GitHub Desktop.
extract *only* unique values from an existing array
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
// private implementation of '[].unique' | |
Array.prototype.unique = function() { | |
var orig = {} | |
, i | |
, il = this.length | |
, res = [] | |
for (i = 0; i < il; i++) orig[this[i]] = this[i] | |
for (i in orig) res.push(orig[i]) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
include this snippet in your code and use it like this...
var array_unique = new Array().unique.call(original_array)