I have two array of objects, they are essentially copies but the reference array uses a different order.
let result = {"articleData":[{"id":"1","identifier":"Article1"},{"id":"2","identifier":"Article2"},{"id":"3","identifier":"Article3"},{"id":"4","identifier":"Article4"},{"id":"5","identifier":"Article5"},{"id":"6","identifier":"Article6"}]};
let resultReference = {"articleData":[{"id":"3","identifier":"Article3"},{"id":"4","identifier":"Article4"},{"id":"1","identifier":"Article1"},{"id":"2","identifier":"Article2"},{"id":"6","identifier":"Article6"},{"id":"5","identifier":"Article5"}]};
What I want to do is: currently I get some data from my API but it is in the wrong order (how it currently is in "result" array). I want the data to be in the exact same order as the "resultReference" array but how can I achieve this? Is there a minimal approach?
https://jsfiddle.net/g1rmhq9f/
Thanks for any advice
.sort()with.findIndex()so you use the index of each element in theresultReferenceto sort your other array. This should do it.