javascript - Using Lodash `_.get` to access object key using bracket notation -
i have following
const key = 'foo'; const test = { foo: { bar: 23 } }; and i'd use lodash get access value of test[key].bar.
i want use bracket notation on first indicator...
_.get(test, '[key].bar'); // results in undefined surely there's way...
you need put value of key path string:
_.get(test, key + '.bar'); in es2015 can use template literal (interpolated string):
_.get(test, `${key}.bar`);
Comments
Post a Comment