Home > Net >  Checking if a value exists in JavaScript Object
Checking if a value exists in JavaScript Object

Time:08-08

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?

CodePudding user response:

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

let valueExists = Object.values(obj).includes("value you looking for");

CodePudding user response:

You can check in the values array

const valuesArray=Object.values(anyObj);
console.log(valuesArray.some((value)=>value.includes('monday'))
  • Related