How to remove duplicates in an Array using ES 2015
Imagine that you have the following array:
And you want it to become this:
Let me introduce
Set is a data object introduced in ES 2015, which lets you store values of any type. A value in the Set may only occur once, making it perfect for what we are trying to accomplish.
Now back to the array we started with.
Let's create a new Set out of it.
Notice how the Set object already made the values unique.
Now convert it back to an array by using the
spread operator (...).
Your array is now distinct, with only unique values!
This can also be done in a one-liner:
It can also be used in more advanced cases, for example with an array of objects.
In this example you'll get an array with the cities only mentioned once.
Detect and style for Dark Mode in CSS
Using very little CSS it is possible to detect wether the user has dark mode enabled or not. With this unexpectedly way you'll ease your visitors eyes.
Npm 7 is now the standard, here is what you'll get
Finally npm 7 is generally available and published as latest in the npm registry. Read up on the differences, new features and performance boosts compared to npm 6.