js 对象根据value获取对应的key

// 根据对象的value值获取key
export const getFindKey = (value: any, obj: any, me: any) => {
let objlist = JSON.parse(JSON.stringify(obj)) ;
delete objlist.me;
let findKey = (value: any, compare = (a:any, b:any) => a === b) =>{
return Object.keys(objlist).find(k => compare(objlist[k], value))
}
return findKey(value);
}
 

 

 

posted @ 2021-01-08 14:06  lipu1993  阅读(5749)  评论(0编辑  收藏  举报