0

I have this multi array with a url and number in each inner array, how do i sort so the array is organized by highest number to smallest.

var arr = [
["http://example.com", "3"],
["http://example.com2", "1"],
["http://example.com3", "22"]
]

i want it to look like this

var arr = [
["http://example.com3", "22"],
["http://example.com", "3"],
["http://example.com2", "1"],
]
0

1 Answer 1

1

You can use .sort function with custom compareFunction, like this

var arr = [
  ["http://example.com", "3"],
  ["http://example.com2", "1"],
  ["http://example.com3", "22"]
];

var res = arr.sort(function (a, b) {
  return b[1] - a[1];
});

console.log(res);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.