My goal is to develop a complex nested structure by combining elements from three arrays.
var obj;
obj = [
{
"a": {
"A" : "aA",
"B" : "aB",
"C" : "aC"
}
},
{
"b": {
"A" : "bA",
"B" : "bB",
"C" : "bC"
}
},
{
"c": {
"A" : "cA",
"B" : "cB",
"C" : "cC"
}
},
]
To achieve this, I have three arrays as follows:
var arr1 = ["a","b","c"]
var arr2 = ["A","B","C"]
var arr3 = [["aA","aB","aC"],["bA","bB","bC"], ["cA","cB","cC"]]
I am wondering if there are any straightforward approaches using lodash or ES6. Even though my current method involves another function that generates 'arr3' from 'arr1' and 'arr2', what other methods can be used to create multi-level nested objects from multiple arrays? Is there any available documentation on this topic for handling more than 3 arrays?
This is what I have attempted so far:
arr1.forEach((item)=>{
arr2.forEach((prop)=>{
obj[item] = {}
obj[item][prop] = prop
})
})