Code: Select all
const arr =[{name: 'Glenn'}, {name: 'Rob'}, {name: 'Ronald'}]
Like so:
Code: Select all
// Rob is now first index
const arr =[{name: 'Rob'}, {name: 'Glenn'}, {name: 'Ronald'}]
Code: Select all
const arr =[{name: 'Glenn'}, {name: 'Rob'}, {name: 'Ronald'}]
Code: Select all
// Rob is now first index
const arr =[{name: 'Rob'}, {name: 'Glenn'}, {name: 'Ronald'}]
Code: Select all
const arr =[{name: 'Glenn'}, {name: 'Rob'}, {name: 'Ronald'}];
let first = 'Rob';
arr.sort((a, b) => (b.name == first) - (a.name == first));
console.log(arr); // [{name: 'Rob'}, {name: 'Glenn'}, {name: 'Ronald'}]