This code works just fine, but could obviously be more elegantly written.
The basic idea is to create an array of categories from a text input. The code splits up the text input by commas to create the array and trims away white space.
I considered using unshift to add the 'Inbox' default category to the beggining, but figure there must be an even better way. All in all, this is probably the 4th or 5th version of this code.
var CategoriesForm = event.target.category.value;
var CategoriesFormTrimmed = CategoriesForm.replace(" ", "");
var categoriesDefault = ['Inbox']; //default category
var categoriesJoined = [];
if (CategoriesForm) {
var splitUpCategories = CategoriesFormTrimmed.split(',');
categoriesJoined = categoriesDefault.concat(splitUpCategories);
console.log(categoriesJoined);
} else {
categoriesJoined = ['Inbox'];
}
camelCase
for everything except constructor functions. So style-wise, yourCategoriesForm
should becategoriesForm
, and the same for the-Trimmed
var. Joseph's answer below sidesteps all those variables anyway, but just as a general note. – Flambino Aug 27 at 8:50