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.