โ02-05-2021 05:47 AM
Hi,
I want to create a 2 sub array from an Array.
Input :
{
โarray1โ:[
{
โItemโ:โPenโ,
โItem Descโ:โBlackโ,
โLengthโ: โ7โ,
โWidthโ: โ2โ,
โWeightโ:โ5โ
}
{
โItemโ:โPenโ,
โItem Descโ:โBlackโ,
โLengthโ: โ7โ,
โWidthโ: โ2โ,
โWeightโ:โ5โ
}
]
}
Output:
{
โArray1โ:[
{
โItemโ:โPenโ,
โItem Descโ:โBlackโ,
โLengthโ: โ7โ,
โWidthโ: โ2โ,
โWeightโ:โ5โ
}
{
โItemโ:โPenโ,
โItem Descโ:โBlackโ,
โLengthโ: โ7โ,
โWidthโ: โ2โ,
โWeightโ:โ5โ
}
]
โArray2โ:[
{
โItemโ: โPenโ,
โItem Descโ:โBlackโ
},
{
โItemโ:โPenโ
โItem Descโ:โRedโ
}
]
}
โ02-05-2021 06:55 AM
Use a mapper, then
For the first array just write $array1 in the expression, and for the second you need this expression: $array1.map(val => {โItemโ: val.Item, โItem Descโ: val[โItem Descโ] })
Result:
โ02-05-2021 02:34 PM
Also, please always use a Preformatted Text block (with the </> icon) for any JSON blocks in your posts.