javascript

Remove Duplicate Values From an Array in JavaScript Using ES6

We can easily get the distinct values in our JavaScript array by using the spread operator.

const arr = [1,1,4,5,5,37,57,28,67,67];
console.warn(arr); // [1,1,4,5,5,37,57,28,67,67]

//With Spread operator
const newArr = [...(new Set(arr)];
console.warn(newArr); //[1,  4,  5, 37, 57, 28, 67]

The spread operator makes it for us to iterate over an array and return distinct values.

7 JavaScript Shortcuts You Should Start Using

Recent Posts

JavaScript Memoization

In JavaScript, it’s commonly used for: Recursive functions (like Fibonacci) Heavy calculations Repeated API/data processing…

1 week ago

CSS Container Queries: Responsive Design That Actually Makes Sense

For years, responsive design has depended almost entirely on media queries. We ask questions like: “If…

1 week ago

Cron Jobs & Task Scheduling

1. What is Task Scheduling? Task scheduling is the process of automatically running commands, scripts,…

1 week ago

Differences Between a Website and a Web App

Here’s a comprehensive, clear differentiation between a Website and a Web App, from purpose all the…

3 weeks ago

Essential VS Code Extensions Every Developer Should Use

Visual Studio Code (VS Code) is powerful out of the box, but its real strength…

4 weeks ago

JavaScript Variables

1. What Is a Variable in JavaScript? A variable is a named container used to store data…

4 weeks ago