Is there a better way to do this?
var duplicate = false;
for (var i = 0; i < acceptedFiles.length; i++) {
for (var j = 0; j < attachments.attachments.length; j++) {
if (attachments.attachments[j].name === acceptedFiles[i].name) {
duplicate = true;
}
}
}
set
of youracceptedFiles
and pass that around. Thus you could remove the outerfor
loop and simply query the set if the attachment is accepted. If you have many accepted types, this could also speed up significantly as you go from \$\mathcal{O}(nk)\$ to \$\mathcal{O}(n)\$. \$\endgroup\$