ネストされたプロパティを持つオブジェクトがある場合。すべてのプロパティ、および他のオブジェクト (独自のプロパティも持つ) である値を持つプロパティなどを検索する関数はありますか?
オブジェクトの例:
const user = {
id: 101,
email: 'help@stack.com',
info: {
name: 'Please',
address: {
state: 'WX'
}
}
}
上記のオブジェクトには、次のようなものを簡単に呼び出す方法があります
console.log(findProp(user, 'state'));
console.log(findProp(user, 'id'));