JSFiddle - React, Tailwind, and code Playground

by ponyspy

JavaScript

var needSort = [ { id: 4, name:'alex' }, { id: 3, name:'jess' }, { id: 9, name:'...' }, { id: 1, name:'abc' } ];
var order = [ 3, 1, 9, 4];

needSort.sort(function(a,b){
    return order.indexOf(a.id) < order.indexOf(b.id) ? -1 : 1;
});

console.log(needSort);