I have a single object in the following array:
[{"IP_Address":"33.4.160.5","originEmailAddress":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f050e020a1c2f18060303061c410c0002">[email protected]</a>"}]
I am looking to destructure it into a two-element array of objects like this:
[{"IP_Address: "33.4.160.5"},{"originEmailAddress": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb919a969e88bb8c9297979288d5989496">[email protected]</a>"}]
Is there an efficient way to achieve this? While I know how to transform it back to the original format, as shown below:
let keys = Object.keys(test[0]);
let values = Object.values(test[0]);
const merged = keys.reduce((obj, key, index) => ({ ...obj, [key]: values[index] }), {});
I am struggling with reducing it into an array of two objects. Any insights would be greatly appreciated.