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

Victor Talmacinschi

How to Convert an Array to a Set in JavaScript

JavaScript by Victor Talmacinschi June 21, 2022

const array = [ '🍎', '🍌', '🍊', '🍋', '🍉', '🍇', '🍓', '🍈', '🍒', '🍑', '🍍', '🥭', '🥥', '🍅', '🍆', '🥑' ];

// convert the array to a Set
const set = new Set(array);

// log the set to the console
console.log(set);

0

16.419

How to Convert an Array to a Set in JavaScript

JavaScript by Victor Talmacinschi June 21, 2022

const foods = ['🌭', '🍕', '🥓', '🌭', '🍔']

// convert array to set
const foodsSet = new Set(foods)

console.log(foodsSet)
// Set(4) {🌭, 🍕, 🥓, 🍔}

0

16.419

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories