So I have a query output somewhat like this (using knex):
response = [
{id: 1, source: 'mobile', ms_payment.id: 111, ms_payment.total: 100},
{id: 2, source: 'mobile', ms_payment.id: 112, ms_payment.total: 210},
...
]
And the expected output (mapped output) to return in REST API is:
result = [
{id: 1, source: 'mobile', ms_payment: { id: 111, total: 100 }},
{id: 2, source: 'mobile', ms_payment: { id: 112, total: 210 }},
]
Is there any efficient algorithm using javascript? I am currently doing it manually with Array.map(), which just returns the expected output schema, without any looping or methods.
Thank you in advance.