Skip to content

Instantly share code, notes, and snippets.

@amitkumar
Created September 4, 2014 22:12

Revisions

  1. amitkumar created this gist Sep 4, 2014.
    13 changes: 13 additions & 0 deletions join-with-commas.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    function joinWithCommas (array){
    var result = '';
    $.each(array, function(index, label){
    if (index === 0){
    } else if (index < (array.length - 1)){
    result += ', ';
    } else {
    result += ' and ';
    }
    result += label;
    });
    return result;
    };