Javascript - sort array based on another array

后端 未结 22 1448
鱼传尺愫
鱼传尺愫 2020-11-22 03:45

Is it possible to sort and rearrange an array that looks like this:

itemsArray = [ 
    [\'Anne\', \'a\'],
    [\'Bob\', \'b\'],
    [\'Henry\', \'b\'],
             


        
22条回答
  •  情歌与酒
    2020-11-22 04:04

    You can do something like this:

    function getSorted(itemsArray , sortingArr ) {
      var result = [];
      for(var i=0; i

    You can test it out here.

    Note: this assumes the arrays you pass in are equivalent in size, you'd need to add some additional checks if this may not be the case.

    refer link

    refer

提交回复
热议问题