I have code like this:
if (view == 'delete' || view =='edit' || view == 'new') {}
Is there a more clean way that I can code this without using an external library. It just does not look too good to have all the || and maybe more later.
I have code like this:
if (view == 'delete' || view =='edit' || view == 'new') {}
Is there a more clean way that I can code this without using an external library. It just does not look too good to have all the || and maybe more later.
Use indexOf (won't work on ancient IE versions):
if (["delete", "edit", "new"].indexOf( view ) >= 0) { alert("ME");}
You can also use regular expression:
if (/^(delete|edit|new)$/.test(view)) {
// true
}