user3821345 user3821345 - 7 months ago 11
Javascript Question

Selecting multiple properties in Javascript or D3

I'm trying to remove a few data points from a map created in D3.

Here I'm removing a property with name matching "Luxembourg", but I would also like to remove a property with name matching "Liechtenstein". How should I write this?

.filter(function(labels) {
return labels.properties.name != "Luxembourg";
})


I have tried using javascript references but I'm having trouble applying these.

Answer

How about using Array.prototype.indexOf

.filter(function(labels) {             
   var toFilter = ['Luxembourg', 'Liechtenstein']
   return toFilter.indexOf(labels.properties.name) !== -1
})
Comments