I have a object as given below:
const obj = {
"[email protected]": "email one",
"[email protected]": "email two",
}
How to get object key if their value matched with given variable:
var outputVal = "email two";
Object.entries(obj ).map(([key,value])=>{
if(outputVal === value){
console.log('output', key);
}
3
Answers
Working fine
You can use find on object
Use
find()
onObject.keys(obj)
Your problem can be simplified by swapping the keys/values around. Just interrogate the object key to get its value.