javascript - Best way to concatenate multiple strings ignoring blank -



javascript - Best way to concatenate multiple strings ignoring blank -

i have input user next family members

mothersname, fathersname, childsname, sibling1name, sibling2name

some of these can skipped , blank. want concatenate non blank entries comma lastly 1 concatenated word "and"

e.g. mary, bob, peter , ellie

what easiest way accomplish this?

something like:

names = ['foo1', '', 'foo2', '', 'foo3'] nonblank = names.filter(function (name) { homecoming name.length !== 0 }) out = nonblank.slice(0, nonblank.length - 1).join(', ') + ' , ' + nonblank.pop() console.log(out); // prints "foo1, foo2 , foo3"

javascript angularjs

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -