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?

3
  • 1
    can you specify if you know at which level of nesting you want to look for it ? Commented Aug 8, 2022 at 13:38
  • 2
    This is neither a React or JSX issue. Just use JS to check to see if anObj.myFoo includes 'MONDAY'. Commented Aug 8, 2022 at 13:39
  • Does this answer your question? How to check whether a string contains a substring in JavaScript? Commented Aug 8, 2022 at 13:39

1 Answer 1

2

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

let valueExists = Object.values(obj).includes("value you looking for");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.