Simply Spread

Simply Spread



πŸ”ž ALL INFORMATION CLICK HERE πŸ‘ˆπŸ»πŸ‘ˆπŸ»πŸ‘ˆπŸ»

































Simply Spread


Sign up with email
Sign up




Sign up with Google



Sign up with GitHub



Sign up with Facebook




Asked
7 years, 2 months ago


15.7k 6 6 gold badges 45 45 silver badges 77 77 bronze badges


80.3k 26 26 gold badges 127 127 silver badges 168 168 bronze badges


290k 25 25 gold badges 350 350 silver badges 357 357 bronze badges



This doesn't work in Safari(8) or Chrome (41). But it does work in Firefox(35) though.

–  425nesp
Apr 2 '15 at 5:33



var array = [v for (v of mySet)]; does not work in chrome 46

–  Eric
Oct 27 '15 at 21:36



I think the most elegant way is simply [...mySet] .

–  Wojciech Bednarski
Mar 10 '16 at 12:49



@WojciechBednarski l33t is not elegant . If any of the examples are that, it's Array.from(mySet);

–  Buffalo
May 4 '17 at 6:35



Just wanted to add that [...mySet] has issues when compiled using Typescript (see this issue ), so probably safer to use Array.from(mySet) if you intend to convert to Typescript in the near future.

–  Ivan Gozali
Mar 11 '19 at 16:24





15.7k 6 6 gold badges 45 45 silver badges 77 77 bronze badges



why a downvote ? are there any problems with this approach ? Or somebody tried to execute this code in IE11 and failed ? ;)

–  c69
Oct 9 '14 at 8:49



I didn't downvote, but I tried this in the latest version of Chrome and failed, so it's not just an IE issue.

–  Meshaal
Mar 19 '15 at 4:45



refer to kangax.github.io/compat-table/es6 for more or less up-to-date support chart. Currently, of all desktop browsers, only FF and IE TP (aka Spartan, aka MS Non-IE browser) support Array.from and ...

–  c69
Mar 19 '15 at 23:58



Looks like Firefox is the only browser to support Array.from . developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

–  425nesp
Apr 2 '15 at 5:27



Here you can enable it for Chrome chrome://flags/#enable-javascript-harmony Remember it's experimental don't think for moment that this is a good solution for development.

–  sospedra
Jun 15 '15 at 11:11





6,350 5 5 gold badges 35 35 silver badges 61 61 bronze badges


322 2 2 silver badges 7 7 bronze badges



Unluckily the only cross-broser solution

–  Marco Sulla
Apr 2 '19 at 8:12


7,885 16 16 gold badges 74 74 silver badges 120 120 bronze badges



It seems that using the set.entries() you will get array of pairs. You can use set.values() to get the plain array.

–  Shimon Rachlenko
Jan 13 '16 at 13:14



@ShimonRachlenko true, and the user did ask for that.

–  Roland
Jan 13 '16 at 16:01



You can just use var array = Array.from(set);

–  Buffalo
May 4 '17 at 6:36



this answer is just wrong. You don't need the call to .entries , nor .values . As @Buffalo mentioned above - Array.from(set) is enough.

–  c69
Oct 23 '18 at 2:12



@c69 that is true. At the time of this answer, Array.from() did not work as expected. But now spread and Array.from() both work just fine.

–  Roland
Oct 23 '18 at 9:50


540 5 5 silver badges 18 18 bronze badges


80.6k 19 19 gold badges 234 234 silver badges 150 150 bronze badges


43.9k 26 26 gold badges 78 78 silver badges 143 143 bronze badges



..and this is what?

–  ZF007
Dec 31 '19 at 11:20


1,381 15 15 silver badges 20 20 bronze badges


1,347 12 12 silver badges 10 10 bronze badges


Stack Overflow

Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness


Products

Teams
Talent
Advertising
Enterprise



Company

About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us



Stack Exchange Network

Technology
Life / Arts
Culture / Recreation
Science
Other


Join Stack Overflow to learn, share knowledge, and build your career.
Set seems like a nice way to create Arrays with guaranteed unique elements, but it does not expose any good way to get properties, except for generator [Set].values, which is called in an awkward way of mySet.values.next() .
This would have been ok, if you could call map and similar functions on Sets. But you cannot do that, as well.
I've tried Array.from , but seems to be converting only array-like (NodeList and TypedArrays ?) objects to Array. Another try: Object.keys does not work for Sets, and Set.prototype does not have similar static method.
So, the question: Is there any convenient inbuilt method for creating an Array with values of a given Set ? (Order of element does not really matter).
if no such option exists, then maybe there is a nice idiomatic one-liner for doing that ? like, using for...of , or similar ?
if no such option exists, then maybe there is a nice idiomatic
one-liner for doing that ? like, using for...of, or similar ?
Indeed, there are several ways to convert a Set to an Array :
Simply spreading the Set out in an array
The old fashion way, iterating and pushing to a new array (Sets do have forEach )
Previously, using the non-standard, and now deprecated array comprehension syntax:
It turns out, we can use spread operator:
Or, alternatively, use Array.from :
Assuming you are just using Set temporarily to get unique values in an array and then converting back to an Array, try using this:
This relies on using underscore or lo-dash .
Perhaps to late to the party, but you could just do the following:
This should work without problems in browsers that have support for ES6 or if you have a shim that correctly polyfills the above functionality.
Edit : Today you can just use what @c69 suggests:
Use spread Operator to get your desired result
Using Set and converting it to an array is very similar to copying an Array...
So you can use the same methods for copying an array which is very easy in ES6
An array and now you can use all methods that you can use for an array...
The code below creates a set from an array and then, using the ... operator.
Here is an easy way to get only unique raw values from array. If you convert the array to Set and after this, do the conversion from Set to array. This conversion works only for raw values, for objects in the array it is not valid. Try it by yourself.

By clicking β€œPost Your Answer”, you agree to our terms of service , privacy policy and cookie policy

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo Β© 2021 Stack Exchange Inc; user contributions licensed under cc by-sa . revΒ 2021.2.3.38486


simply spread - Russian translation – Linguee
javascript - How to convert Set to Array? - Stack Overflow
Simply spread cold butter - YouTube
Simply Spread Spanish Translation - Examples Of Use Simply Spread In...
ES6 magical stuffs β€” Spread (…) syntax in depth | by Maya Shavin | Medium

Ass 0 Ass
Naked Play
Lesbi Outdoor
Naughty America Watch
Private Static C

Report Page