teddy1995
teddy1995

Reputation: 61

Search for a JavaScript method to exclude elements

I found this startsWith method to select and filter 'keys' and then do something with the dataset in JavaScript,but now I look for a method which is the opposite of

str.startsWith(searchString[, position])

For example, I only want to display datasets which don't have a key which starts with 'article'.

const data = Object.entries(y)
  .filter(([key, value]) => (key.startsWith(!"article")))
  .map(([key, value]) => {}

the "!" Sign didn't work here. Does JavaScript offers a better nethode?

Upvotes: 0

Views: 182

Answers (1)

David
David

Reputation: 219047

This doesn't make sense:

!"article"

You don't want to negate the value of the string, you want to negate the value retuned by .startsWith(). Semantically you want "not starts with" ("doesn't start with"):

!key.startsWith("article")

Upvotes: 2

Related Questions