Skip to content

Instantly share code, notes, and snippets.

@ishu3101
Created September 22, 2016 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishu3101/caac7720bf611423ea0cdbb9242b6b5b to your computer and use it in GitHub Desktop.
Save ishu3101/caac7720bf611423ea0cdbb9242b6b5b to your computer and use it in GitHub Desktop.
Turn a Javascript Array Into a Human Readable String. See http://rogerstringer.com/2015/02/22/javascript-pretty-array-to-human-readable-string/
var items = ["item1","item2","item3","item4"];
console.log(humanify(items));
function humanify(array){
if( array.length > 1 ){
return array.slice(0,-1).join(', ') + ' & ' + array[array.length -1];
}
return array[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment