Created
November 29, 2016 02:54
-
-
Save samueleastdev/ca5946b2295eb09ca2e85eed1a738760 to your computer and use it in GitHub Desktop.
Filter out unique array of objects and return full object using array filter
This file contains hidden or 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
var dt = [{"address":"Caër, 27930 Normanville, France","longitude":1.172397,"latitude":49.066906},{"address":"Caër, 27930 Normanville, France","longitude":1.172397,"latitude":49.066906},{"address":"Same, Tanzania","longitude":37.750342,"latitude":-4.0666225},{"address":"Caerphilly CF83, UK","longitude":-3.218134,"latitude":51.578829},{"address":"Caerphilly CF83, UK","longitude":-3.218134,"latitude":51.578829},{"address":"Caerphilly CF83, UK","longitude":-3.218134,"latitude":51.578829},{"address":"Caerphilly CF83, UK","longitude":-3.218134,"latitude":51.578829},{"address":"Caër, 27930 Normanville, France","longitude":1.172397,"latitude":49.066906}]; | |
var flags = {}; | |
var dt = dt.filter(function(entry) { | |
if (flags[entry.address]) { | |
return false; | |
} | |
flags[entry.address] = true; | |
return true; | |
}); | |
console.log(dt); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment