将数组中某个对象提到第一位

将type=-1的对象提到第一位:
let  orglist = [//原数组
  {name:a,type:0},
  {name:b,type:1},
  {name:c,type:-1},
  
]
 
orglist.forEach((item,idx)=>{

 

            if(item.type == -1){
              orglist.splice(idx,1)
              orglist.splice(0,0,item)
            }

 

          })
 
console.log(orglist)得到
[//新数组
  {name:c,type:-1},
  {name:a,type:0},
  {name:b,type:1},
  
  
]
posted @ 2020-12-09 14:46  shez  阅读(1488)  评论(0编辑  收藏  举报