需求是:如果数组的name相同,就比较下timestamp,哪个比较大保留哪个,小的去掉。数组如下:
var arr = [
{name: "袜子", timestamp: 1537243392},
{name: "月饼", timestamp: 1537243369},
{name: "月饼", timestamp: 1537243411},
{name: "女鞋", timestamp: 1537243241},
{name: "童鞋", timestamp: 1537243204},
];
希望得到的数组结果是:
var finalArr = [
{name: "袜子", timestamp: 1537243392},
{name: "月饼", timestamp: 1537243411},
{name: "女鞋", timestamp: 1537243241},
{name: "童鞋", timestamp: 1537243204},
];
一个原始的版本