Sort one array the same way as another array JavaScript

后端 未结 4 1175
日久生厌
日久生厌 2021-01-12 16:42

I have 2 arrays:

[2, 4, -2, 4, 1, 3]
[\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]

and I want them to be sorted by the numerical array:

<
4条回答
  •  轮回少年
    2021-01-12 17:36

    I would recommend storing the entire thing in a Map. That way, you can independently sort the first array however you want and then use those values as keys to call respective value of second array.

提交回复
热议问题