const arr = [1, 3, 4, 2, 7];
const arrObj = [
{
key: 2
},
{
key: 1
},
{
key: 4
},
{
key: 3
},
{
key: 7
},
{
key: 2
}
];
const res = arrObj.sort(this.sortFunc('key', arr));
console.log(res, 'res');
sortFunc(propName, referArr) {
return function (prev, next) {
return (
referArr.indexOf(prev[propName]) - referArr.indexOf(next[propName])
);
};
},