Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

format string of names

function list(names) {
  var xs = names.map((p) => p.name);
  var x = xs.pop();
  return xs.length ? xs.join(", ") + " & " + x : x || "";
}

// Example:
// list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])
// returns 'Bart, Lisa & Maggie'
 
PREVIOUS NEXT
Tagged: #format #string #names
ADD COMMENT
Topic
Name
1+6 =