场景:有数组arr,需要根据obj对象里面的managerId来排序arr数组的顺序,如果obj里面的managerId在arr数组里面是在第4位,就把arr里面的第四个数据排序到第一个来,代码如下:
<script>
var arr = [{
managerId: "xiaohong",
managerName: "小红"
}, {
managerId: "xiaobai",
managerName: "小白"
}, {
managerId: "xiaohuang",
managerName: "小黄"
}, {
managerId: "xiaozhang",
managerName: "小张"
}, {
managerId: "xiaolan",
managerName: "小兰"
}, {
managerId: "xiaopan",
managerName: "小潘"
}, {
managerId: "xiaodeng",
managerName: "小登"
}, {
managerId: "xiaoshui",
managerName: "小水"
}]
var obj = {
clientSource: "4",
createBy: "robot",
createDate: "2019-12-12 00:00:00",