I wish to sort an array of three strings in a specific order.
book, car and wheel.
I can receive these strings in any order.
There may be one or more strings - max three
I would like to sort the strings in the following exact order if one or more strings are received.
wheel, book, car
assume the property name is name...
I tried something like this:
myitem.sort((a, b) => {
if(a.name === 'wheel')
return 1;
if(a.name === 'book' && b.name === 'car')
return 1;
return -1;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…