//编写代码对"fruits"数组进行深度复制 并 按id升排序
//深度复制一个数组
//按照属性id进行排序 sort函数
const fruits = [
{id:43, title:'Apple', price:12}, {id:21, title:'Banana', price:5},
{id:13, title:'Orange', price:8}, {id:55, title:'Mango', price:15},
{id:44, title:'Grape', price:10}, {id:6, title:'Peach', price: 14}
]
let copy = fruits.slice();
console.log(copy.sort(function (a, b){return a.id-b.id}));
输出:
[
{ id: 6, title: ‘Peach’, price: 14 },
{ id: 13, title: ‘Orange’, price: 8 },
{ id: 21, title: ‘Banana’, price: 5 },
{ id: 43, title: ‘Apple’, price: 12 },
{ id: 44, title: ‘Grape’, price: 10 },
{ id: 55, title: ‘Mango’, price: 15 }
]