I have a function that accepts two args - an object, and a value. I want to check if the object contains the given value.
For example:
{a: "b", c: "d"}
Contains value "d" as key c stores it.
I have a function that accepts two args - an object, and a value. I want to check if the object contains the given value.
For example:
{a: "b", c: "d"}
Contains value "d" as key c stores it.
You can use Object.values to get the values of the object and check if the value passed is in them using includes.
var containsValue = function(val, obj){
return Object.values(obj).includes(val);
};
console.log(containsValue("Jim", {name: "Jim", course: "FEDev"}));
console.log(containsValue("Jim", {name: "Nope", course: "FEDev"}));