Created
September 22, 2016 08:27
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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