1

I am trying to search for any object key that has the value of "*" Not the wildcard character, but the string "*".

How do I escape the asterisk in the following code? currently (and rightly so) this returns every property in the object.

keys = Object.keys(fullListObj).filter((k) => fullListObj[k] === 'n/a' || '*');
Yenmangu
  • 71
  • 9

1 Answers1

2

I think that your error was that you forgot to add this check fullListObj[k] === "*" What you did is you asked if fullListObj[k] === "n/a" or "*" and "*" is a string that is not empty so this will always evaluate to true.

You should change it to this:

keys = Object.keys(fullListObj).filter(
  (k) => fullListObj[k] === "n/a" || fullListObj[k] === "*"
);
EkkoKo
  • 214
  • 1
  • 5