In my react app, I have an API that returns data in this format: set.child.child
and it can keep on going (set.child.child.set.child.child
) depending on how many layers the data return has. I have a string that holds the path of that data and I need a way to get the data based on the string.
So for example, I have a string that holds the path of where I need the data at.
const dataPath = "tableData.rows[0].set.child[1].child"
.
Here's what I can do: I can run
tableData.rows[0].set.child[1].child.map
Here's what I need to do:
dataPath.map
I had thought there would have been a way to convert dataPath
to act as a value that could be mapped over. I was thinking you could do something like {dataPath
}.map or maybe there was a type of parse I could use but I can't seem to find anything to do this.