Why does Javascript Set not do unique objects?

Another option is you could use JSON.stringify() to keep your object unique, that way it is comparing against a string instead of an object reference.

set.add(JSON.stringify({name:'a', value: 'b'}))

and then after everything is formatted you can just parse those lines back to an array like this:

const formattedSet = [...set].map(item) => {
  if (typeof item === 'string') return JSON.parse(item);
  else if (typeof item === 'object') return item;
});

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)