Back to Browse

Stop Writing for Loops for This (Use .includes() Instead)

87 views
Sep 15, 2025
9:38

🛒 Building a shopping cart in JavaScript? Before adding an item, you need to check if it's already in the cart. Most beginners write long loops, use flags, and overcomplicate the logic. But there’s a cleaner way: ✅ Use .includes() — a simple, one-line method that checks if an item exists in an array. In this video, I’ll show you: The wrong way most beginners write this logic How .includes() makes your code readable and reliable Why writing less JavaScript can actually make you a better developer 💡 Use this trick for: Shopping carts User roles Blocklists And any array-based lookup! ⚡ Sometimes, the best coding tips aren’t about what to add… They’re about what to remove. 📌 If you’re learning JavaScript, check out my full series on array methods and clean coding strategies. 🔔 Subscribe for weekly JavaScript tips & tutorials. 💬 Comment below: Have you used .includes() before? #JavaScript #CleanCode #LearnJavaScript #JavaScriptTips #CodingForBeginners #ShoppingCartJS #ArrayMethods

Download

1 formats

Video Formats

360pmp416.7 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Stop Writing for Loops for This (Use .includes() Instead) | NatokHD