我有这样的数组
var arr = ["hub","master","hub","transit","transit","master"];
我想将上面的数组重新排序为特定的顺序,如
var arr = ["master","hub","hub","master","transit","transit"];
例如,如果我得到像
这样的数组Ex1:
var a = ["hub","transit","master","master"];
result = ["master","hub","master","transit"];
Ex2:
var a = ["hub","master"];
result = ["master","hub"];
我知道使用for循环检查项目在哪个位置并推入新数组但我想使用更优化的方式。
任何想法......谢谢