HomeTutorsContact

How to convert Set to Array in JavaScript?

By Gulshan Saini
Published in JavaScript
October 28, 2020
1 min read

Let’s say you have following Set of numbers, which you want to convert to array.

One way of converting a Set to Array is using Array.from() method

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

Another, way of converting a Set to array is using spread operator.

To convert set variable we will wrap it inside square brackets and spread the variable as follows

Both the approach work fine and the results are same.

Output

console.log(array) // (11) [1, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12]

Tags

#javascript
Previous Article
How to get all unique values in a JavaScript array?

Gulshan Saini

Fullstack Developer

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to get all unique values in a JavaScript array?

October 27, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media