I need to combine the LAST fromAddress and toAddresses values into just one set of array without duplication and without the loginUser.
Expected Output
{ "newResponse": ["james@gmail.com", "ken@yahoo.com"] }
const loginUser = "jane@gmail.com"
const old = [
{
"toAddresses": ["joker@gmail.com", "jake@gmail.com"],
},
{
"fromAddress": "ken@yahoo.com",
"toAddresses": ["jane@gmail.com", "james@gmail.com"],
}
];
let emailLength = old?.length - 1
let email = old[emailLength]
const newResponse = Array.from(new Set([...email.map(x => [...x.toAddresses].concat([...x.fromAddress || []]))]))
console.log(newResponse)