Access property via it's keyPath in Javascript?
问题 I have data = { 'first': { 'number': 1, 'text': 'Ya.' }, 'second': { 'number': 10, 'text': 'Da.' } }; And I really want to access it like: number = data['first.number']; Actually in a more flexible way, like: numberOrText = data[memberName+'.'+propertyName]; Is there any lightweight library, or snippet you can suggest? This is - https://github.com/martinvl/KVCObject - so cool, but a bit overhead for this. 回答1: You can easily resolve keypath with reduce function , without using any library.