JS数组对象,指定的对象置顶或者置底
//置顶、至底部
recordChange(record,type){
function moveToFirst(arr, item) {
const index = arr.indexOf(item);
if (index !== -1) {
arr.unshift(arr.splice(index, 1)[0]);
}
}
function moveToLast(arr, item) {
const index = arr.indexOf(item);
if (index !== -1) {
arr.push(arr.splice(index, 1)[0]);
}
}
let targetItem = this.tableData.find((el) => el.id === record.id);
if(type=='top'){
moveToFirst(this.tableData, targetItem);
}else{
moveToLast(this.tableData, targetItem);
}
},