How to convert a set to an array in Chrome?

How to convert Set to Array? gives three answers for converting a set into an array, none of which currently work in the Chrome browser.

Let's say I have a simple Set

var set_var = new Set(['a', 'b', 'c']); 

I can iterate through my variable and add elements to an empty array

 var array_var = []; set_var.forEach(function(element){array_var.push(element)}); 

But are there other ways to do this with broader browser support?

+7
javascript google-chrome
source share
1 answer

Why not try installing an iterator?

 function setToArray(set) { var it = set.values(), ar = [], ele = it.next(); while(!ele.done) { ar.push(ele.value); ele = it.next(); } return ar; } setToArray(new Set(['a', 'b', false, 0, 'c'])); // ["a", "b", false, 0, "c"] 
+1
source share

All Articles