Sort two dimensional array : Two Dimensional Array « Data Type « JavaScript DHTML






Sort two dimensional array

 <html> <head> <title>Array literal</title> <script type="text/javascript" > function compare(a, b) { return a[1] - b[1]; } var planets = [ ['A', 0.3], ['B', 0.9], ['C', 1], ['D', 0.8], ['E', 2.4] ]; planets.sort(compare); document.write(planets); </script> </head> <body> </body> </html> 








Related examples in the same category

1.Another way to declare the two-dimensional array
2.Use nested for loop to loop through the two-dimension array
3.Use two-dimensional array to store matrix data
close