Question

I'm using http://api.geonames.org/findNearbyPostalCodes to get all zip codes in a radius of 20km of the zip code which a user types in a textbox. If the user types in textbox "8280" it finds all zip codes nearer than 20km away of "8280". But for some cities or villages it returns the same zip code.

Now I'm wondering if there is a function or if it is possible to do it with JavaScript to check if some zip codes are double.

I'm googling the whole day but I could not find anything. Can someone give me a hint?

Était-ce utile?

La solution

If they aren't already contained in an array, you could add them to one and then use the filter method to remove the duplicates:

var arr1 = [33333, 90201, 87678, 45665, 343144, 17645, 67503, 48796, 37657, 33333, 45665];

var deduped = arr1.filter(function(elem, pos) {
  return arr1.indexOf(elem) == pos;
});

console.log(deduped); // [33333, 90201, 87678, 45665, 343144, 17645, 67503, 48796, 37657]

Demo.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top