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
let obj = { a: 1, b: { c: 2 }, d: [1, 2, 3, 4], e: [{ f: [5, 6] }] } let r1 = parse(obj, 'a') let r2 = parse(obj, 'b.c') let r3 = parse(obj, 'd[2]') let r4 = parse(obj, 'e[0].f[0]')
new Function
function parse(obj, str) { let fn = new Function('obj', 'return obj.' + str) return fn(obj) }
split
function parse(obj, str) { str = str.replace(/\[(\d+)\]/g, '.$1') let arr = str.split('.') arr.forEach(item => { obj = obj[item] }) return obj }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
实现方案1
new Function
实现方案2
split
The text was updated successfully, but these errors were encountered: