Skip to content

Instantly share code, notes, and snippets.

@davidpots
Created January 19, 2015 01:51
Show Gist options
  • Select an option

  • Save davidpots/92c2357a82a15471fd91 to your computer and use it in GitHub Desktop.

Select an option

Save davidpots/92c2357a82a15471fd91 to your computer and use it in GitHub Desktop.

Revisions

  1. davidpots created this gist Jan 19, 2015.
    10 changes: 10 additions & 0 deletions Add item to array if it doesn't exist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // On a page with many .item elements, where each element has many tags .item__tag
    // This will create an array 'tagList' that contains all tags (without duplicates)

    var tagList = [];
    $.each( $('.item__tag'), function(i,obj) {
    nextTag = obj.innerText;
    if ($.inArray(nextTag,tagList) == -1) {
    tagList.push( nextTag );
    }
    } );