Let’s say you have following
Set of numbers, which you want to convert to array.
let set = new Set([1, 1, 3, 4, 3, 5, 6, 7, 8, 9, 0, 11, 12, 3])
One way of converting a
Array is using
The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.
let array = Array.from(set)
Another, way of converting a
Set to array is using spread operator.
set variable we will wrap it inside square brackets and spread the variable as follows
let array = [...set]
Both the approach work fine and the results are same.