How to convert a Set to an Array in JavaScript-Code Examples

Victor Talmacinschi

How to convert a Set to an Array in JavaScript

JavaScript by Victor Talmacinschi June 21, 2022

// convert a Set to an Array in JavaScript

// using the spread operator
const set = new Set(['🍎', '🍌', '🍊']);
const arr = [...set];

console.log(arr); // [ '🍎', '🍌', '🍊' ]

// using Array.from()
const set = new Set(['🍎', '🍌', '🍊']);
const arr = Array.from(set);

console.log(arr); // [ '🍎', '🍌', '🍊' ]

0

16.507

How to convert a Set to an Array in JavaScript

JavaScript by Victor Talmacinschi June 21, 2022

const mySet = new Set(['🌟', '🌟', '🌟', '🌟', '🌟']);

// convert to an Array
const myArray = Array.from(mySet);

console.log(myArray); // [ '🌟', '🌟', '🌟', '🌟', '🌟' ]

0

16.507

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories