Find item in array and set as first index
Posted: 24 Nov 2020, 06:49
Say I have the following array of persons:
And I want to find a certain person (name) in this array, and put it as the first index in the array if it exist.
Like so:
How can I achieve this in a simple way?
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'}]