Sorting an Array according to the order of another Array

I have an array with sizes like this: var arr = [ 'small', 'small', 'small', 'small', ... 'medium', 'medium', 'medium', 'medium', ... 'big', 'big', ... ]; I need to reorganize this array according to this order: var order = ['small', 'small', 'medium', 'medium', 'big']; So the result ends up being something like this: var arr = [ 'small', 'small', 'medium', 'medium', 'big', 'small', 'small', 'medium', 'medium', 'big' ... ]; I'm aware of other similar questions in SO but I couldn't find anything so far. I'm unsure how to approach this. I was thinking `sort` should do but what do I test for? It seems simple but I'm stuck, don't know where to begin. Any hints?
I think you need to show an actual example of the array before and after. Right now I cannot see what makes the array split on the two sets you are showing in the output

以上就是Sorting an Array according to the order of another Array的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏