To use JavaScript lodash push to an array only if value doesn’t exist, we use sets.
For instance, we write
const s = new Set();
s.add("hello");
s.add("world");
s.add("hello");
to create a set with the Set
constructor.
And then we call add
to add 'hello'
and 'world'
.
'hello'
won’t be added a 2nd time since it already exists.