How can I change the order of values within each element of an array?

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"
}
]

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

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).

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