1
I have four arrays A,B.C, and D. For example:

// example code is here length of a is 1 length of b is 4 length of c is 1 length of d is 2.

    var a = [1];
    var b = [2,3,4,5];
    var c = [6];
    var d = [7,8];

I want to order those four arrays based on the larger length of the arrays, so the arrays will be in order: b,d,a,c. 
Novis
  • 630
  • 4
  • 13
  • 28

1 Answers1

1

Modded from: Sort an array based on the length of each element

Hope this is what you are looking for.

<script>
arr = [];
arr[0] = [1];
arr[1] = [2,3,4,5];
arr[2] = [6];
arr[3] = [7,8];

arr.sort(function(a, b){
return b.length - a.length; // ASC -> a - b; DESC -> b - a
});
alert(arr.join('\n'));

</script>
Community
  • 1
  • 1
BriOnH
  • 945
  • 7
  • 18
  • If this answers your question I would appreciate it if you could mark it as such. – BriOnH Jan 27 '14 at 18:40
  • is it possible to display the name of the array as well with the output. – Novis Jan 27 '14 at 18:41
  • You have a bunch of questions that you have asked on StackOverflow with great answers, and you have marked none of them as answers to your questions. – BriOnH Jan 27 '14 at 18:51
  • how to mark them. i dont know exactly how to do that. Could you please tell me that? – Novis Jan 27 '14 at 19:06
  • If you ask a question and someone answers it you click the big checkmark. In this case it would be below the "0" and the vote up, and vote down icons, to the upper left of where I (and about 10 others to your other questions on here) began my answer to your problem. Also if you like a question or an answer that isn't yours and it has helped you, vote it up by clicking the up icon (in this case above the big 0 to the upper left of my answer). Also do this with comments as well. StackOverflow runs on a reputation point system. – BriOnH Jan 27 '14 at 19:23