cancel
Showing results for 
Search instead for 
Did you mean: 

Creating one more field in list of objects by using the fields in same objects

GBekkanti
New Contributor III

Hi Team,
I have the below input data :
[
{
ID:123
“Name”:“Tony”,
“Age”:24
},
{
ID:124
“Name”:“Sam”,
“Age”:36
},
{
ID:125
“Name”:“Glenn”,
“Age”:58
}]

I need to add one more field ‘halfAge’ to the above and output data should be like below:

[
{
ID:123
“Name”:“Tony”,
“Age”:24,
“halfAge”:12
},
{
ID:124
“Name”:“Sam”,
“Age”:36
“halfAge”:18
},
{
ID:125
“Name”:“Glenn”,
“Age”:58,
“halfAge”:29
}]

Can you please let me know the Expression language for this?

Thanks in Advance!

7 REPLIES 7

One of the functions available in the expression language is zip, which enables you to merge two arrays. Does this help?

42

cjhoward18
Employee
Employee

@GBekkanti

sounds like you want to do something like this which you can do using sl.zip()

sl.zip($items, $genderArray).map(pair => pair[0].extend({ Gender: pair[1] }))

GBekkanti
New Contributor III

Thanks @cjhoward18, @cstewart

It works fine. Thank you