I would like to know how to get the array object based on values in javascript.
I have array object obj1, obj2 , how to get the object if name of obj1 matches with obj2 values in javascript
var obj1=[
{name: "country", value: "countries"},
{name: "city", value: "cities"}
]
var obj2=[
{countries:"countries"},
{sample: "sample"}
]
var result = this.getMatchedObj(obj1, obj2);
function getMatchedObj(obj){
const newlist = obj1.map((elem) => obj2.find(e=>Object.values(e)===elem.value));
return newlist;
}
Expected Output:
[
{name: "country", value: "countries"}
]