首页 > > > js如何查找对象中某个value路径上的key?
let obj = {
key1: 'str1',
key2: {
key3: 'str3'
},
key4: {
key5: {
key6: 'str6',
key7: 'str7'
},
key8: 'str8'
},
key9: 'str9'
};有这样一个对象,要求封装一个函数,传入对象和某个 value,返回该 value 路径上的 key。比如:searchKeys(obj, 'str3'),得到 'key3, key2'。这是前几天面试时遇到的题,求高手解答
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4687/viewspace-3118979/ ,如需转载,请注明出处,否则将追究法律责任。