I have a multi-dimensional object data
, and I want to fetch a given branch of it via a string. Example:
data = {
title: 'Hi',
topics: {
title: 'Yey',
general: {
topics: {
description: 'Desc'
}
}
}
The dimensions of the object are variable. What I want is to be able to import the whole object, and then dynamically pick the branch I want, like so:
import data from './dataFile'
let branchString = 'data.topics.general'
let myBranch = data + branchString // this obviously doesn't work
Thanks in advance.