function executeCode(obj, params) { const str = `(${params})=>${obj.slice(1)}` return new Function(`"use strict";return (${str})`)()(Function('"use strict";return (' + params + ')')()) } const cus = { xx:'c', query:{ a:123, b:{ c:'cccc' } } } console.log(cus.query.b.c) console.log(executeCode('=cus.query.b.c','cus')) console.log(executeCode('=cus["query"]["a"]','cus')) const cc = 'c' console.log(executeCode('=cus["query"]["b"][cus.xx]','cus'))