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

How to Filter Vulgar Words in React Native

If you're building a social, chat, or comment-based mobile app using React Native, protecting your…

6 days ago

How to Build Faster Mobile Apps With Native Wind Library

The Cross-Platform ImperativeLet's face it: building separate iOS and Android apps wastes resources. React Native…

1 week ago

The Surprisingly Simple Secret to Getting Things Done

We live in an age of infinite distraction and overwhelming ambition. Grand goals shimmer on…

1 week ago

How to Create Reusable Components in React JS

Reusable components are modular UI building blocks designed for versatility. Instead of writing duplicate code…

1 week ago

Check if Number, Word or Phrase is a Palindrome in JavaScript

What is a Palindrome? A palindrome is any word, phrase, number, or sequence that reads…

2 weeks ago

How Facial Recognition Software Works

Facial recognition technology is rapidly changing how we interact with devices, access services, and enhance…

3 weeks ago