JSFiddle - React, Tailwind, and code Playground
JavaScript
var arr = ['one','four','two'];
var test = [{
key: 'one'
},{
key: 'two'
},{
key: 'four'
}];
function sortFunction(a,b){
var indexA = arr.indexOf(a['key']);
var indexB = arr.indexOf(b['key']);
if(indexA < indexB) {
return -1;
}else if(indexA > indexB) {
return 1;
}else{
return 0;
}
}
alert(test[1]['key']);
test.sort(sortFunction);
alert(test[1]['key']);