Unique Array Values
When you look at any programming language, you see missing features that you find puzzling because the use case seems so common. One such case is retrieving unique values from an array with JavaScript. Years ago I mentioned an easy way of unique value management using objects instead of arrays, but that's not always an option and doesn't match every use case.
Want to retrieve a unique array of values from an array that may include duplicate values? You can use new JavaScript spread operator with Set to get an array of unique values:
var j = [...new Set([1, 2, 3, 3])]
>> [1, 2, 3]
Getting unique array values is another awesome usage of the spread operator. And don't forget you can merge object properties with the spread operator!
There's no better feeling than being able to remove a library to complete a task that should be native to the language. This trick brings us one step closer to that!
![Interview with a Pornhub Web Developer]()
Regardless of your stance on pornography, it would be impossible to deny the massive impact the adult website industry has had on pushing the web forward. From pushing the browser's video limits to pushing ads through WebSocket so ad blockers don't detect them, you have...
![5 More HTML5 APIs You Didn’t Know Existed]()
The HTML5 revolution has provided us some awesome JavaScript and HTML APIs. Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers. Regardless of API strength or purpose, anything to help us better do our job is a...
![MooTools TwitterGitter Plugin]()
Everyone loves Twitter. Everyone loves MooTools. That's why everyone should love TwitterGitter, a MooTools plugin that retrieves a user's recent tweets and allows the user to format them however the user would like. TwitterGitter allows the user to choose the number of...
![CSS Circles]()
A while back I shared a clever technique for creating triangles with only CSS. Over the past year, I've found CSS triangles incredibly effective, especially when looking to create tooltips or design elements with a likewise pointer pattern. There's another common shape...
If you’re forced to stay in EC5-land without the spread operator, you can use the pollyfillable
Array.from()
Doesn’t seem to work for arrays of objects unless I’m missing something.
If your array is an object, you can use map function, to get the value in an array.
then you can run method like above.
Anybody using babel with this one should be cautious, this will result in an array with a single set element. Patrick Denny’s is the most predictable form.
Thanks David! Very helpful! :)