In both cases, the input isn't logical. Any value supplied to attrKey at any level should be a simple object with out nested arrays or sub-objects. Likewise all charkey values should be a string. That isn't the case with these two examples which is why they produce strange outputs. However, ideally, there should be some sort of validation to check for these cases and produce errors in these cases.
Consider the following code:
Observe that the output is
In both cases, the input isn't logical. Any value supplied to
attrKey
at any level should be a simple object with out nested arrays or sub-objects. Likewise allcharkey
values should be a string. That isn't the case with these two examples which is why they produce strange outputs. However, ideally, there should be some sort of validation to check for these cases and produce errors in these cases.