[Solved] How to list array names in json [closed]


You are misunderstanding usage of data types. Array is an anonymous type, you don’t name it’s elements. If you want to know name of an array, then you must change this structure to a dictionary (map).

var arrayMapping = {
'arr1': [...],
'arr2': [...]
};

But by doing so remember that every array will have unique name. You will then could access your arrays like so:

arrayMapping['array1']

But if for some reason you can’t change this data structure then you need to create a help object, where you are mapping names to arrayIndex. But that will increase code complexity, and will need to be wrapped in some sort of util class with getters.

If your array contains 5 arrays and you want to get to them by name, then you need this sort of a structure:

var arrayMapping = {
'arr1': {
   'arr1_1': [],
   'arr1_2': [],
   'arr1_3': [],
   'arr1_4': [],
   'arr1_5': [],
    },
...
};

Not if you want to list all anmes of arrays that are inside arr1 map, then you should do something like this:

 Object.keys(arrayMapping['arr1'])// it will list arr1_1,...,arr1_5

2

solved How to list array names in json [closed]