Skip to content

Convert Array to Set in JavaScript

var arr = [1, 2, 3, 4, 5, 1, 2];
var set = new Set(arr);
console.log(set); //(5) { 1=> 1,2=> 2,3=> 3,4=> 4,5=> 5 }
console.log(set.size === arr.length);  //false

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.