var db=[ ["A","B"], ["B","B"], ["B","A"], ["A","A"] ] db.sort(function(a,b){ return a[1] > b[1] }) alert(db.join('\n'))