I have the following code:
$(document).on('change', 'input.authority-email', function() {
var authorityValues = $(this);
var authorityArray = [].map.call(authorityValues, function (authorityValues) {
return authorityValues.value;
}).join(',');
$('input#team_authority_emails').val(authorityArray);
});
$(document).on('change', 'input.member-email', function() {
var memberValues = $(this);
var memberArray = [].map.call(memberValues, function (memberValues) {
return memberValues.value;
}).join(',');
$('input#team_member_emails').val(memberArray);
});
My thoughts are that this process isn't very DRY and could be a single separate function?
[].map.call(memberValues, function (memberValues) {
return memberValues.value;
}).join(',');
var authorityArray = [].map.call(authorityValues, function (authorityValues) {
return authorityValues.value;
}).join(',');
What is the best way to create a function that can create and return my array? Or are there any other improvements I can make to this?
mapmethod here? There is only one element! Why not simplythis.value?input.member-email. The database expects the values (emails) returned in the following format: [email protected], [email protected], etc. The values are returned to a hidden field.thisis going to only equal the value that changed, not the full set of values.