0

if i have an array of values, and an array of characters

var values = [31, 11, 10, 51]
var chars = ['a', 'b', 'c', 'd']

i then sort the values array with .sort

values.sort(function(a, b){return a-b}); // result: [10, 11, 31, 51]

if i then want the chars array to be sorted to match the values array - how do i go about doing that ?

so that the result will be:

 // wanted result
 [10, 11, 31, 51] 
 ['c','b','a','d']
Anders Pedersen
  • 2,255
  • 4
  • 25
  • 49
  • The answer can be found in [an older post](http://stackoverflow.com/questions/12199051/merge-two-arrays-of-keys-and-values-to-an-object-using-underscore) – Ludovic Frérot Mar 21 '16 at 10:00
  • var arr = [ {value:31, chars: 'a'}, {value:11, chars: 'b'}, {value:10, chars: 'c'}, {value:51, chars: 'd'}]; arr.sort(function(a, b) { return a.value - b.value; }); console.log(arr); – Shwetha Mar 21 '16 at 10:00

0 Answers0