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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -