var to = ['user1', '@user2', 'user3@email.com']
The following codeset should keep 'user1' in the to
array, remove the '@' from the start of '@user2', and move 'user3@email.com' to the toEmail
array
Right now, else if (toName[j] == '@') {
is logging 'syntax error'
var toEmail = [];
var pushToEmail;
for (i=0; i<to.length; i++) {
var pushToEmail = false;
var toName = to[i];
for (j=0; j<toName.length; j++) {
if (toName[0] == '@') {
toName[0] = toName[0].replace(/@/g, ''); // remove '@''
}
console.log('toName[0] = ' + toName[0]);
else if (toName[j] == '@') {
pushToEmail = true;
break;
}
}
if (pushToEmail == true) {
toEmail += to.splice(INDEX, 1)[i];
}
}
You have a syntax error. You can't just throw a console.log
in the space between an if
and an else
. The else
has to be attached to an if
statement, you've tried to attach that else
to a console.log
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.