Given a JS object
(给定一个JS对象)
var obj = { a: { b: '1', c: '2' } }
and a string
(和一个字符串)
"a.b"
how can I convert the string to dot notation so I can go
(如何将字符串转换为点表示法,以便我可以)
var val = obj.a.b
If the string was just 'a'
, I could use obj[a]
.
(如果字符串只是'a'
,我可以使用obj[a]
。)
But this is more complex.(但这更复杂。)
I imagine there is some straightforward method but it escapes at present.(我想有一种简单的方法,但是目前可以逃脱。)
ask by nevf translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…