Skip to content
Advertisement

Send multiple strings as separated values

I want to make multiple emails as strings to be separated values. I’m trying something like this:

sendInquiry: function () {
                const id = '459875';
                const inquiry = {
                    to: 'info@user-mail.com' && 'info@admin-mail.com',
                    senderEmail: this.form.email,
                    senderName: this.form.name,
                    subject: this.form.subject,
                    pN: this.form.personNum,
                    message: this.form.message
                };
}

What am I doing wrong? How to correctly send them ​​to be separated?

Advertisement

Answer

'info@user-mail.com' && 'info@admin-mail.com' is interpreted as a boolean by javascript. Indeed, a no void string is true, so 'info@user-mail.com' && 'info@admin-mail.com' is true.

To pass multiple strings the optimal data structure is an array, of course you can concat multiple strings into one (1) but it is easier to work with arrays because of the integrated methods builded in javascript.

Knowing that you should do :

sendInquiry: function () {
  const id = '459875';
  const inquiry = {
    to: ['info@user-mail.com', 'info@admin-mail.com'],
    senderEmail: this.form.email,
    senderName: this.form.name,
    subject: this.form.subject,
    pN: this.form.personNum,
    message: this.form.message
  };
}

(1) or use any other type of data

Advertisement