We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function get(obj, ...args) { // ... } const obj = { selector: { to: { toutiao: 'FE coder' } }, target: [1, 2, { name: 'byted' }] }; get(obj, 'selector.to.toutiao', 'target[0]', 'target[2].name'); // 输出结果:// ['FE coder', 1, 'byted']
The text was updated successfully, but these errors were encountered:
function getValue(source, path, defaultValue = null) { const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.'); let result = source; for (let key of paths) { // null 与 undefined 取属性会报错, 用Object包装一下 result = Object(result)[key]; } return result || defaultValue; } function get(obj, ...args) { return args.map(key => getValue(obj, key)); }
Sorry, something went wrong.
No branches or pull requests
题目
The text was updated successfully, but these errors were encountered: