Why are the outputs of these two code snippets different when adding objects to a set affects reference comparison?
let list = [ {a:1,b:1},{a:2,b:3},{a:3,b:1} ]
let set = new Set(list);
let newList = [{a:1,b:2},{a:3,b:1}];
set.add(...newList)
let newFilteredList = [...set]
console.log(newFilteredList)
Another Code Example:
let list = [ {a:1,b:1},{a:2,b:3},{a:3,b:1} ]
let newList = [{a:1,b:2},{a:3,b:1}];
let employees = [...list, ...newList]
let set = new Set(employees)
let newFilteredList = [...set]
console.log(newFilteredList)
Output for First Code:
(4) [{...}, {...}, {...}, {...}]
0 : (2) {a: 1, b: 1}
1 : (2) {a: 2, b: 3}
2 : (2) {a: 3, b: 1}
3 : (2) {a: 1, b: 2}
[[Prototype]] : []
Output for Second Code:
(5) [{...}, {...}, {...}, {...}, {...}]
0 : (2) {a: 1, b: 1}
1 : (2) {a: 2, b: 3}
2 : (2) {a: 3, b: 1}
3 : (2) {a: 1, b: 2}
4 : (2) {a: 3, b: 1}
[[Prototype]] : []