0

Learning JSX here and I was wondering if theres a way to check if a value appears in a object in JavaScript

i.e We have an obj: anObj ={ myFoo : "MONDAY;TUESDAY;WEDNESDAY" }

How could I check if monday etc appears in this object?

Andy
  • 61,948
  • 13
  • 68
  • 95
  • 1
    can you specify if you know at which level of nesting you want to look for it ? – Alaa Eddine Cherif Aug 08 '22 at 13:38
  • 2
    This is neither a React or JSX issue. Just use JS to check to see if `anObj.myFoo` [`includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) 'MONDAY'. – Andy Aug 08 '22 at 13:39
  • Does this answer your question? [How to check whether a string contains a substring in JavaScript?](https://stackoverflow.com/questions/1789945/how-to-check-whether-a-string-contains-a-substring-in-javascript) – kemicofa ghost Aug 08 '22 at 13:39

1 Answers1

1

You can find the value in Object.values with .includes()

let valueExists = Object.values(obj).includes("value you looking for");
Grant Solomons
  • 181
  • 1
  • 1
  • 11