I hope, that I used terms right, I will explain anyway.
So the idea is:
Here is a 'dictionary' (it's an array of id's of DOM elements
, but i suppose this doesn't matter)
['foo', 'evil', 'banana']
And here's an array of objects:
[
{id: 'evil', data: 'somedata'},
{id: 'foo', data: 'dataagain?'},
{id: 'banana', data: 'somemoredata'}
]
I think You already get it.
I want to sort this array of objects in the way its id's
will be in the same order as corresponding elements in 'dictionary'.
As elegant and as fast as possible, obviously. jQuery
or plain JavaScript
.
For the moment i can only think about splice trickery, like looking up for place of key and then splicing object out and back in to required place.
To make myself completely clear, I want this array of objects at the end to look like this:
[
{id: 'foo', data: 'dataagain?'},
{id: 'evil', data: 'somedata'},
{id: 'banana', data: 'somemoredata'}
]