search

Home  >  Q&A  >  body text

JavaScript 俩数组,个数一样,怎么a数组升序对另一个数组排序?

var a = [ 0 , 89 ,2 , 3];

var b = [ "三月" , "四月" , "五月" , "六月"];var c = [ "01" , "05" , "15" , "16"];

怎么用 a 给 b 升序重新排序呢?


男神男神2791 days ago1035

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 01:06:11

    JavaScript Two arrays have the same number. How can array A sort the other array in ascending order? - PHP Chinese Q&A - JavaScript Two arrays have the same number. How can array A sort the other array in ascending order? - PHP Chinese Online Q&A

    Take a look around and learn.

    reply
    0
  • 迷茫

    迷茫2017-03-24 09:16:17

    要是我理解了你的问题, 你是希望这样吧:

    var a = [ 0 , 89 ,2 , 3];
    
    var b = [ "san" , "si" , "wu" , "liu"];
    
    var merge = a.map(function(ai, i){
        return {a:ai, b:b[i]};
    })
    merge.sort(function(am1, am2){
        return am1.a - am2.a
    })
    // 允许生成新的数组引用就用map, 要是不允许生成新的数组引用,就挨个赋值
    b = merge.map(function(ab, i){
        return ab.b
    }) 
    console.log(b);

    reply
    0
  • Cancelreply