📌  相关文章
📜  javascript 将数组元素移到前面 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:56.802000             🧑  作者: Mango

代码示例3
const data= [{code:"001",name:"Kirk-Patrick Brown"},{code:"002",name:"Sara Brown"},{code:"003",name:"Joe Frazer"}];

const firstItem = "003";
data.sort((x,y)=>{ return x.code === firstItem ? -1 : y.code === firstItem ? 1 : 0; });

console.log(data);