I'm currently working on an email application that allows users to send messages. Everything is functioning well except for the recipients column. I temporarily hardcoded an email address to test the functionality, but in reality, the recipients field should be an array.
What would be the most efficient way to convert multiple addresses entered by a user into JSON format within a form?
The snippet below demonstrates my current approach.
Thank you!
const element = document.getElementById('sendEmail');
element.addEventListener('click', function() {
fetch('/emails', {
method: 'POST',
body: JSON.stringify({
recipients: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f7c7e6d7b2a2e6c77706d6b5f78727e7673317c7072">[email protected]</a>',
subject: document.querySelector('#compose-subject').value,
body: document.querySelector('#compose-body').value
})
})
.then(response => response.json())
.then(result => {
// Print result
console.log(result);
});
});
}