The last few weeks I have been learning Python. I'm following this roadmap: 30-days-of-python Series' Articles by @arindam Dawn. I recommend it ! I love it π€©
Anyway, when I was learning Python I saw that the SET framework existed, and I was fascinated.
But thanks to that I discovered that it also existed in Javascript, and I didn't know it!
With SET we can remove duplicate elements from an array in a very easy way.
JavaScript's built-in Set object is described as a collection of values, where each value may occur only once. A Set object is also iterable, making it easily convertible to an array using the spread (...) operator.
π Here are some examples of this:
const nums = [1, 2, 2, 3, 1, 2, 4, 5, 5, 6, 4, 2, 6];
[...new Set(nums)] // [1, 2, 3, 4, 5, 6]
const something = ['anto', 'anto', 'antonella', 'ant', 'ant', 2, 4, 5, 6,2,2];
[...new Set(something)] // [ 'anto', 'antonella', 'ant', 2, 4, 5, 6 ]
const emojisFruits = ['π','π', 'π ','π' ,'π ','π' ,'π','π','π ','π'];
[...new Set(emojisFruits)] // [ 'π', 'π ', 'π', 'π', 'π', 'π ' ]
Very useful!!!
Did you also know about this?