As people by now pointed out in the comments, you need to use .set()
to insert elements into the map, and .values
to get them out again. Otherwise you are actually butchering your Map object with additional fields that don't belong there, but certainly don't do want you want, namely use the properties of Map.
let conns = [
{"jobId":"BPOM","id":{"makeupUID":"4"}},
{"jobId":"BPOM","id":{"makeupUID":"3"}},
{"jobId":"BPOM","id":{"makeupUID":"2"}},
{"jobId":"BPOM","id":{"makeupUID":"1"}}];
console.log(`Before: ${JSON.stringify(conns)}`)
let unique = new Map();
for (let item of conns) {
unique.set(item.id.makeupUID, item);
}
this._allConnections = Array.from(unique.values());
console.log(`After: ${JSON.stringify(this._allConnections)}`)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…