I have an array how build like this:
"list": [
{
"insideList": [{"code": "0", "image": "./images/1"},
{"code": "1", "image": "./images/2"},
{"code": "2", "image": "./images/3"}],
"bucket": "info",
"instructions": "first set".\n",
"color": "rgb(242, 242, 140)",
"id": "a",
"text": "first quest"
},
...
I'm trying to flatten this list with lodash, but I dont know how to map inside map when the first map also do things. that what i did for the outer loop:
var withIndex = _.map(list,(item, i) => ({
[`iv_${i}_text`]: item.text,
[`iv_${i}_instructions`]: item.instructions,
[`iv_${i}_color`]: item.color,
[`iv_${i}_id`]: item.id,
[`iv_${i}_bucket`]: item.bucket,
}));
but now i want to add the inside loop on 'aspects' list and build something like this:
var withIndex = _.map(list,(item, i) => ({
[`iv_${i}_text`]: item.text,
[`iv_${i}_instructions`]: item.instructions,
[`iv_${i}_color`]: item.color,
[`iv_${i}_id`]: item.id,
[`iv_${i}_bucket`]: item.bucket,
[`iv_${i}_a_0_code`]: item.insideList[0].code,
[`iv_${i}_a_0_image`]: item.insideList[0].image,
[`iv_${i}_a_1_code`]: item.insideList[1].code,
[`iv_${i}_a_1_image`]: item.insideList[1].image,
[`iv_${i}_a_2_code`]: item.insideList[2].code,
[`iv_${i}_a_2_image`]: item.insideList[2].image
}));
It is possible to do something like this using lodash?
var withIndex = _.map(list,(item, i) => ({
[`iv_${i}_text`]: item.text,
[`iv_${i}_instructions`]: item.instructions,
[`iv_${i}_color`]: item.color,
[`iv_${i}_id`]: item.id,
[`iv_${i}_bucket`]: item.bucket,
and here do another map:
_map(insideLoop, (item, j)=> ({
[`iv_${i}_a_{j}_code`]: item.insideList[0].code,
[`iv_${i}_a_{j}_image`]: item.insideList[0].image,
[`iv_${i}_a_{j}_code`]: item.insideList[1].code,
[`iv_${i}_a_{j}_image`]: item.insideList[1].image,
[`iv_${i}_a_{j}_code`]: item.insideList[2].code,
[`iv_${i}_a_{j}_image`]: item.insideList[2].image
}));