How to create a unique list of elements using the Set object

Creating unique lists in javascript is a common task, this is usually achieved by applying filters or for loops, but there is another way to accomplish this leveraging the Set object.

const list = [1, 2, 3, 5, 2, 5, 7]; 
const uniqueList = [ Set(list)];

We pass the array of primitive values to the Set object; it creates a collection of unique values which is then converted to a list using the spread operator syntax and array literals.

You can also read this

How to apply single quotes around every value using VS code?

I often work with large documents and very often I...


Simple Nodejs watcher

I built a simple Nodejs watcher that is syncing changes...

const dataCsv = './sample_data.csv';
const mongodb = require("mongodb").MongoClient;
const csvtojson = require("csvtojson");
const fs = require('fs');
let url = "mongodb://yoururl";