Roket
April 8, 2021, 11:41am
1
Hey!
How can I change the order of values within each element of an array?
State A:
"Оплата":
[
{
"ПорядковыйНомер": 1,
"ВариантОплаты": "Кредит (плановый)",
"ДатаПлатежа": "20210409",
"СуммаПлатежа": 50000
}
]
State B:
"Оплата": [
{
"ПорядковыйНомер": 1,
"СуммаПлатежа": 100000,
"ВариантОплаты": "Кредит (плановый)",
"ДатаПлатежа": "20210409"
}
]
ivov
April 8, 2021, 11:54am
2
One option:
return [].concat(
...items.map(i => i.json.Оплата.map(({ ПорядковыйНомер, СуммаПлатежа, ВариантОплаты, ДатаПлатежа }) => {
return { json: { ПорядковыйНомер, ВариантОплаты, ДатаПлатежа, СуммаПлатежа } };
}))
);
1 Like
Hey @Roket !
You can also use the Set node to do this, if you don’t want use the Function node. Below is an example:
1 Like
Roket
April 8, 2021, 12:01pm
4
harshil1712, thanks for your attention to my problem, but this does not work in this case, i.e. in a set node it is possible to swap places only within a type (number or string or boolean).
Roket
April 8, 2021, 12:08pm
5
Sorry for the quick conclusions about your solution, everything works even if you use the string type for the input data number.
1 Like
No issues! I am glad that it works for you!
Have fun