cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to Create a subArray from an Array

sjakathi
New Contributor II

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โ€
}
]
}

2 REPLIES 2

j_angelevski
Contributor III

Use a mapper, then
image

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:
image

ptaylor
Employee
Employee

Also, please always use a Preformatted Text block (with the </> icon) for any JSON blocks in your posts.