Sorting two dimentional array and displaying result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • codehelp55
    New Member
    • Feb 2009
    • 1

    Sorting two dimentional array and displaying result

    Code:
    function abc()
    {
    	var tstr1 = new Array();
    	var vari=50;
    	var htmlText  ='';
    
    		for(var i=0; i<vari; i++)
    		{
    			tstr1.push(["a" + i, "second value" + i]);
    		}
    
    					tstr1.sort(function(a, b) 
    								{	//sorting first value in alphabetical order and the associated value
    								  return a[0] < b[0]
    									? -1
    									: a[0] == b[0]
    									  ? 0
    									  : 1
    									;
    								}
    							);
    
    
    					for(var t=0; t<tstr1.length; t++)
    					{
    						//creating html to display value1 and value 2
    						htmlText = htmlText + "<li>" + tstr1[t][0] +"----------" + tstr1[t][1] +"</li>";
    					}
    					htmlText = "<ul>" + htmlText + "</ul>";
    					document.write(htmlText);
    					
    }
    Last edited by Dormilich; Feb 6 '09, 10:04 PM. Reason: added [code] tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    and what exactly is the problem?

    Comment

    Working...