0

filtering data for a visualization I noticed that some values that do not correspond exactly to the values contained in the filter are not passed. what I would like to do is to filter all the values in my dataset that contain that word, now i have:

stile.filter(function (d) { return d.StyleName == "Bold" || d.StyleName == "Demi" || d.StyleName == "Semibold"; });

I thought that adding the .contains() at the end of each value I want filtered could do the trick, like so:

stile.filter(function (d) { return d.StyleName.contains("Black") || d.StyleName.contains("Heavy") || d.StyleName.contains("Extrabold") || d.StyleName.contains("BoldNonextended"); })

But this didn't work unfortunately. Any help as always is really appreciated, thanks!

EDIT: my dataset is a csv, the StyleName column has vairous values, like: Bold, Bold Extended, Regular and so on. If I use the filter function that I have now, the data row containing Bold Extendend for example, is not returned because it has the word Extended also in it. That's what I'm trying to solve

2
  • Can you post some example data and expected output with your question? Commented Nov 25, 2013 at 17:25
  • added in the edit, it should be more clear now Commented Nov 25, 2013 at 17:30

1 Answer 1

4

Instead of contains try using match() and regular expressions:

stile.filter(function (d) { return d.StyleName.match(/Black/) || d.StyleName.match(/Heavy/) || d.StyleName.match(/Extrabold/) || d.StyleName.match(/BoldNonextended/); })
Sign up to request clarification or add additional context in comments.

1 Comment

thanks it works! looks like I have to look into regular expressions again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.