Skip to content
Advertisement

Javascript – sort array based on another array

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

JavaScript

to match the arrangement of this array:

JavaScript

Unfortunately, I don’t have any IDs to keep track on. I would need to priority the items-array to match the sortingArr as close as possible.

Update:

Here is the output I’m looking for:

JavaScript

Any idea how this can be done?

Advertisement

Answer

One-Line answer.

JavaScript

Or even shorter:

JavaScript
Advertisement