It looks like you want to have programmatic access to a deep data structure, where the path is determined by parsing a text query with a specific syntax - in your case, . as a path delimiter. It shouldn't be hard to implement a recursive function to drill down into the data structure using the path, but the main issue - from your example - is that the first item on the path describes a variable - and you can't programmatically search for a variable in the current context: you can only look for keys in objects. For example, if the settings variable is a window property, then you can start your search from the window object.
So basically you want to create a method that takes the root object (for example, window, as discussed above), look at the first element of the path and see if there's a property in that object with that name, and if so - call itself again with the result and the rest of the path.
A naive implementation might look like so:
function searchPath(object, path) {
let [prefix, rest] = path.split(".",2);
if (object[prefix] !== undefined) {
if (rest.length > 0)
return searchPath(object[prefix], rest);
return object[prefix];
}
return undefined;
}
api_response.key.split('.').reduceRight((obj, key) => ({ [key]: obj }), api_response.val)