我有一个数组对象,and如果它能在该数组中找到,我想返回它,否则它将返回or我只想返回值而不是键。
目前它返回对象并且我只需要值。
const arrObj = [
{
"relation_type": "undefined"
},
{
"relation_type": "or"
},
{
"relation_type": "and"
},
{
"relation_type": "or"
},
{
"relation_type": "or"
}
]
let obj = arrObj.find((o) => {
if (o.relation_type === "and") {
return true;
}
});
console.log(obj);Run Code Online (Sandbox Code Playgroud)
感谢您的支持!
你可以这样做:
let obj = arrObj.find(o => o.relation_type === "and") ? "and" : "or"