Skip to content

Instantly share code, notes, and snippets.

@zacharysyoung
Last active April 23, 2021 20:04
Show Gist options
  • Save zacharysyoung/864ef93bbd32c90070632c2c3afc5a57 to your computer and use it in GitHub Desktop.
Save zacharysyoung/864ef93bbd32c90070632c2c3afc5a57 to your computer and use it in GitHub Desktop.
Find and deal with cells in the spreadsheet that have multiple email addresses
/*
You can run this in Chrome by:
1. going to View > Developer > Developer Tools
2. find the "Console" tab
3. copy all the stuff below in one chunk, and paste into the console
4. hit <Enter>
After that you can modify a line by copying it and pasting onto new a line and hitting <Enter> to re-run that line
*/
// How a cell w/multiple emails might look, extra spaces exagerated
var emailCell = ' person1@gmail , person2@outlook , person3@hotmail';
// Split the emails by the separator, a comma in our case
var splitEmails = emailCell.split(',');
console.log('After split:');
console.log(splitEmails);
// Get count of emails
var numberOfEmails = splitEmails.length;
console.log(`Found ${numberOfEmails} email address(es) in emailCell`)
// If we want to key off the individual emails, we need to standardize/normalize...
// Get rid of the extra "whitespace"
var trimmedEmails = [];
for (const email of splitEmails) {
const trimmedEmail = email.trim();
trimmedEmails.push(trimmedEmail);
}
console.log('After trim:');
console.log(trimmedEmails);
// If you want to print/console.log(), it might be easier to read the emails as
// one String and not as elements of an Array
rejoinedEmails = trimmedEmails.join(' / ')
console.log('Re-joined emails: ' + rejoinedEmails);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment