I did edit the original article slightly to indicate that it works with scalar (primitive) values. But I hadn't really thought of this as much of a "gotcha", because two objects that look the same... are not the same.
FWIW, this approach actually works with arrays and objects, if they are truly the same array/object. In other words, you can do something like this:
Came here to comment that. @bytebodger you might want to add that as a catch.
Because this particular gotcha has been a pain for me earlier.
I did edit the original article slightly to indicate that it works with scalar (primitive) values. But I hadn't really thought of this as much of a "gotcha", because two objects that look the same... are not the same.
FWIW, this approach actually works with arrays and objects, if they are truly the same array/object. In other words, you can do something like this:
And the resulting
noDupes
array will only contain one object. But if you do this:noDupes
will contain two objects. Because, even thoughanObject
andanotherObject
look the same to our eye, they are not the same value.