"JavaScript Tricks: Remove Duplicates & Flatten Arrays"

✨ Today I learned something simple but powerful in JavaScript — Removing duplicates & flattening arrays! These two tricks help keep your data clean and easy to work with. 🚀 🔹 Remove Duplicates from an Array Using Set (fast & clean): const numbers = [1, 2, 2, 3, 4, 4, 5]; const uniqueNumbers = [...new Set(numbers)]; console.log(uniqueNumbers); // [1, 2, 3, 4, 5] --- 🔹 Flatten a Nested Array Using flat(): const nested = [1, [2, [3, 4]], 5]; const flatArray = nested.flat(2); console.log(flatArray); // [1, 2, 3, 4, 5] --- 🔥 These small improvements help write cleaner, more readable code. If you're learning JavaScript, definitely try these out! #JavaScript #Learning #WebDevelopment #CodingJourney #100DaysOfCode

To view or add a comment, sign in

Explore content categories