How to sort arrays with multiple items - Javascript -


what trying sort 3 arrays (array1, array2, , array3) in order 0th term, display following.

1, banana, 2, grapes, 3, oranges. 

this code, can't figure out how sort way want.

var array1 = ["1", "banana"]; var array2 = ["3", "oranges"]; var array3 = ["2", "grapes"]; var array4 = [];  function myfunction(){     array4.push(array1, array2, array3);     alert((array4).sort(function(a, b){return a-b})); } 

sort elements based on [0]th index.

(array4).sort(function(a, b){return a[0]-b[0]}) 

function myfunction(){     array4.push(array1, array2, array3);     alert((array4).sort(function(a, b){return a[0]-b[0]})); } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -