You can easily get an array of unique values through this trick. Let’s understand it with the help of an example.
This trick will help you filter false values(o, undefined, null, false, etc.) out of an array. This is a kind of a secret trick as not many people are aware of it.
Students can easily remove duplicate items from an array by using Sets along with a Spread operator. Here’s how to do it.
const removeDuplicateItems = arr => [...new Set(arr)];
removeDuplicateItems([42, 'foo', 42, 'foo', true, true]);//=> [42, "foo", true]
You can’t just miss this awesome trick for requiring values be passed for a given argument.
Students write gross regular expressions to get query strings however, they can enter the URL Search Params API too. This will save their time as well as is easy to do. Just try writing this simple code.
Students generally use DELETE command to remove an item from the array. However, this command replaces the item with undefined instead of completely removing it. You can use the SPLICE command instead. Here’s how to do it.
Till then, keep programming!