JSFiddle - React, Tailwind, and code Playground
JavaScript
function payload(order) {
return {
OrderId: order.ORDERID,
Lines: order.ITEMS.reduce(function(filtered, item) {
if (item.DispatchedNumber != undefined) {
var newItem = {
Qty: item.Qty,
QtyShipped: item.DispatchedNumber
}
filtered.push(newItem);
}
return filtered;
})
}
}
test = payload({
"ORDERID": 1233,
"ITEMS": [
{ Qty: 123, DispatchedNumber: 111 },
{ Qty: 111 },
{ Qty: 444, DispatchedNumber: 555 },
{ Qty: 443, DispatchedNumber: 323 }
]
})
console.log(JSON.stringify(test, null, 2));