I have the following JavaScript data structure. a[] is an array with text strings as elements. It is not
known in advance what it contains. For example,
a = ["foo", "bar", "baz"...];
res{} is a JSON object with as many keys as elements in “a” with the following rule; the last innermost key of res{} is an object with
an array called features[] or the last innermost key itself is an array. So, if , then res is either
// if
a = ["foo", "bar"];
// then
res = {
"foo": {
"bar": {
"features": []
}
}
};
// and I want
data = res["foo"]["bar"].features;
// or
res = {
"foo": {
"bar": []
}
};
// and I want
data = res["foo"]["bar"];
As I said, it is not know in advance how long a[] is or what the values of its elements is. How can I do the above?
Update: fixed a typo in the structure of res
This works ok
You may want to call it with a copy of the keys-array, as the function shifts elements off of the array it’s passed. I.e.