I have some array thats looks like this
let array = ['RANDOM', 'TEST', 'DSVEN','VEN','TEST','SVEN'];
What I need is to sort array based on his values, new array should look like this
let newArray = ['SVEN','DSVEN','VEN' **ETC.**];
it does not matter what order will be at the end, all I need is that array starts with those three elements. Keep in mind that initial array is just example it can me sorted different, but final result should be like newArray
I know I can pass function in sort, but I don't know what to check and how to sort, maybe i need some loop. I don't know the correct way, maybe sort can not even do this?
array.sort(comparefunction)
Thanks in advance
const newArray = [...array]; for (const str of ['VEN', 'DSVEN', 'SVEN']) newArray.unshift(newArray.splice(newArray.indexOf(str), 1)[0]);