胡说叔叔
您可以使用 aMap并使用想要的键存储最后一个对象,然后仅获取最后存储的对象。var array = [{ id: 1, index: 0 }, { id: 2, index: 1 }, { id: 3, index: 2 }, { id: 2, index: 3 }, { id: 3, index: 4 }, { id: 1, index: 5 }, { id: 4, index: 6 }, { id: 5, index: 7 }], result = Array.from(array.reduce((m, o) => m.set(o.id, o), new Map).values());console.log(result);.as-console-wrapper { max-height: 100% !important; top: 0; }如果你想保持原来的顺序,你可以检查相同的对象引用进行过滤。var array = [{ id: 1, index: 0 }, { id: 2, index: 1 }, { id: 3, index: 2 }, { id: 2, index: 3 }, { id: 3, index: 4 }, { id: 1, index: 5 }, { id: 4, index: 6 }, { id: 5, index: 7 }], map = array.reduce((m, o) => m.set(o.id, o), new Map), result = array.filter(o => o === map.get(o.id));console.log(result);.as-console-wrapper { max-height: 100% !important; top: 0; }