We’ve all been there debugging a perfectly fine API response... only to realize your data is failing validation because of a few invisible spaces. These trailing spaces can silently break string comparisons, UI bindings, and even backend validations. So, I wrote a simple recursive utility in JavaScript to clean them deeply. 🧹 𝗪𝗼𝗿𝗸𝘀 𝗳𝗼𝗿: Nested objects Arrays Deeply nested strings 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿𝘀 𝗹𝗼𝘃𝗲 𝗮𝘀𝗸𝗶𝗻𝗴 𝗮𝗯𝗼𝘂𝘁: Recursion Object traversal Data normalization or deep cloning This question can easily appear as: “Write a function to remove spaces from all string values in a nested object.” #JavaScript #WebDevelopment #CodingTips #Frontend
How to remove trailing spaces from nested objects in JavaScript
More Relevant Posts
-
🚀 What if Promise.all(), .map(), and for-await-of had a baby? 👉 Read the full story: https://lnkd.in/dkmmS6Vt Meet Array.fromAsync() — the new JavaScript superpower that makes async data handling clean, declarative, and effortless. No more juggling between loops, maps, or promise chains — just one beautiful one-liner: ```Example``` const users = await Array.fromAsync(ids, fetchUser); `````` ✨ It’s like: - Promise.all() — because it runs async tasks in parallel - .map() — because it transforms each element - for-await-of — because it handles async iterables All rolled into one ergonomic API. 💫 🧠 In my latest article, I dive deep into: - Real-world use cases - Async generator magic Why this small feature changes how we think about async in JavaScript 👉 Read the full story: https://lnkd.in/dkmmS6Vt #JavaScript #ES2023 #WebDevelopment #Frontend #AsyncProgramming #CodingTips #WebTechJournals #LearningMindset #ContinuesGrowth #FrontendDevelopment #PublicisSapient #PublicisGroupe
To view or add a comment, sign in
-
-
Partition Array by Predicate (Fast & Simple) Need to split data into two buckets—approved vs rejected, in-stock vs out-of-stock, active vs inactive? Use a tiny partition helper to divide an array into [pass, fail] in one sweep. It’s fast, readable, and perfect for real-world lists and filters. Why it’s production-ready Single pass over data (O(n)) Preserves original order in both buckets Works with primitives or objects (any predicate) Drop it into your toolkit and keep your array logic clean. ⚡ #JavaScript #VanillaJS #Arrays #CleanCode #WebDev
To view or add a comment, sign in
-
-
Day 10, and I’ve moved on from simple lists (arrays) to managing complex data with JavaScript Objects! If arrays are just numbered lists, objects are like personalized file folders that let you organize information using descriptive names (keys) instead of numbers. This is how you structure anything with multiple properties like a user profile or a product all inside one clean variable. I learned the two main ways to grab information from them: Dot Notation (e.g., user.name) and Bracket Notation (e.g., user['email']). It feels like the final piece of the data organization puzzle! When you’re dealing with objects in JavaScript, when is it necessary or better to use Bracket Notation over Dot Notation?" #objects #javascript #31dayschallenge #growth #frontend #webdevelopment
To view or add a comment, sign in
-
-
🔥 JS Loops Demystified: for vs for…in vs for…of If you’ve ever wondered which loop to use in JavaScript, you’re not alone. Choosing the wrong one can cause subtle bugs! Here’s a quick guide: 1️⃣ Classic for loop – The old reliable const arr = [10, 20, 30]; for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } Use when you need index access, or want full control over iteration. 2️⃣ for…in loop – Iterate over keys (property names) const arr = [10, 20, 30]; for (let key in arr) { console.log(key); // 0, 1, 2 } Works on objects too. ⚠️ Can be dangerous for arrays — also loops over inherited properties. 3️⃣ for…of loop – Iterate over values const arr = [10, 20, 30]; for (let value of arr) { console.log(value); // 10, 20, 30 } Perfect for arrays, strings, maps, sets. Safe, clean, and readable. 💡 Pro tip: Use for when you need the index. Use for…of for values (most array iterations). Avoid for…in on arrays — reserve it for objects. Small choice, huge impact on readability and bug prevention. #JavaScript #CodingTips #WebDevelopment #FrontendDev #CleanCode #JSProTips #ForOfVsForIn
To view or add a comment, sign in
-
#30DayMapChallenge | Day 13 - 10 minutes map If I only have 10 minutes to make a web map, I'll be making it as simple as possible. My Thought Process 🤔 1. HTML, CSS and JS. 2. Leaflet or any other libraries as long as you cover the core components for visualization 3. then source of Data, either in JSON or API's fetch. 4. It should be working at least few bugs. It doesn't have to be complicated like adding react and typescript or other complicated stuffs. Target first the core concept of what you will be making then the complicated stuffs will follow as you grow building it. So how do you simplify your maps? share it below
To view or add a comment, sign in
-
𝐄𝐯𝐞𝐫 𝐰𝐨𝐧𝐝𝐞𝐫𝐞𝐝 𝐰𝐡𝐞𝐫𝐞 𝐲𝐨𝐮𝐫 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 𝐚𝐜𝐭𝐮𝐚𝐥𝐥𝐲 𝐥𝐢𝐯𝐞? Let’s make it super simple. Imagine your brain has two spaces — a tiny desk for quick tasks and a big cupboard for storing bulky stuff. That’s exactly how JavaScript manages memory 👇 🧠 𝕊𝕥𝕒𝕔𝕜 𝕄𝕖𝕞𝕠𝕣𝕪 = The Desk This is where small, quick items go — numbers, strings, booleans. It’s fast, neat, and clears up right after you’re done. 𝚕𝚎𝚝 𝚗𝚊𝚖𝚎 = "𝙰𝚗𝚊𝚜"; 𝚕𝚎𝚝 𝚊𝚐𝚎 = 𝟸𝟼; Both variables fit nicely on the stack. 📦 ℍ𝕖𝕒𝕡 𝕄𝕖𝕞𝕠𝕣𝕪 = The Cupboard This is for bigger and more complex things — objects, arrays, functions. It takes more space and time to access. 𝚕𝚎𝚝 𝚞𝚜𝚎𝚛 = { 𝚗𝚊𝚖𝚎: "𝙰𝚗𝚊𝚜", 𝚊𝚐𝚎: 𝟸𝟼 }; The object is stored in the heap, but a reference to it sits in the stack. ⚖️ In short: Stack → fast, organized, for simple data Heap → flexible, powerful, for dynamic data Understanding this helps you write cleaner code, avoid memory leaks, and truly know what happens “under the hood.” #JavaScript #CodingTips #WebDevelopment #LearnInPublic #Frontend #AnasKhan
To view or add a comment, sign in
-
-
🚀 Ever wondered why a for loop with var logs 3,3,3 — but the same loop with let logs 0,1,2? It’s not magic — it’s JavaScript’s scoping and binding behavior at play 👇 🧩 The Classic Mystery for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000); } // Output: 3, 3, 3 for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000); } // Output: 0, 1, 2 💡 The Hidden Truth var is function-scoped, so it creates one single binding for the entire loop. ➜ All 3 callbacks share the same i. ➜ By the time they run, i = 3. let is block-scoped — and in a for loop, JavaScript creates a fresh binding per iteration. ➜ Each callback remembers its own copy of i. ➜ So it prints 0, 1, 2. ⚙️ Behind the Scenes You can imagine it like this: 🧠 var → One shared box 🧳 🧠 let → A new box every iteration 📦 When the async setTimeout runs later, all var callbacks open the same box (value = 3), while each let callback opens its own box (0, 1, 2). ✅ What You Should Use In modern JavaScript: 🔹 Always prefer let or const over var. They give cleaner scoping, fewer bugs, and predictable async behavior. 💬 Have you ever debugged this “3,3,3” issue before? Drop your story or how you solved it ⬇️ #JavaScript #WebDevelopment #Coding #JSDeepDive #Frontend #Developers #LearnInPublic
To view or add a comment, sign in
-
-
𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗰 𝗦𝗲𝗺𝗶𝗰𝗼𝗹𝗼𝗻 𝗜𝗻𝘀𝗲𝗿𝘁𝗶𝗼𝗻 (𝗔𝗦𝗜) 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 --> 𝘁𝗵𝗲 “𝗵𝗲𝗹𝗽𝗳𝘂𝗹” 𝗳𝗲𝗮𝘁𝘂𝗿𝗲 𝘁𝗵𝗮𝘁 𝘀𝗼𝗺𝗲𝘁𝗶𝗺𝗲𝘀 𝗵𝗲𝗹𝗽𝘀 𝗮 𝗹𝗶𝘁𝘁𝗹𝗲 𝘁𝗼𝗼 𝗺𝘂𝗰𝗵. JavaScript automatically inserts semicolons (;) when it thinks you forgot them. Sounds convenient. Well... sometimes it can change your code’s meaning entirely! 𝗛𝗲𝗿𝗲’𝘀 𝗮 𝗰𝗹𝗮𝘀𝘀𝗶𝗰 𝗲𝘅𝗮𝗺𝗽𝗹𝗲 👇 function getData() { return { message: "Hello World" } } console.log(getData()); You’d expect it to log { message: "Hello World" } 𝗕𝘂𝘁 𝘀𝘂𝗿𝗽𝗿𝗶𝘀𝗲 --> It logs undefined 𝗪𝗵𝘆? Because ASI inserts a semicolon right after return return; // inserted automatically { message: "Hello World" } So the function actually returns nothing. 𝗧𝗼 𝗳𝗶𝘅 𝗶𝘁: function getData() { return { message: "Hello World" } } 𝗧𝗶𝗽: Always keep the return and the value on the same line. ASI is like that friend who “fixes” your code but never tells you what they changed. Always use semicolons intentionally, not accidentally. #JavaScript #WebDevelopment #Frontend #CleanCode #DevCommunity
To view or add a comment, sign in
-
Remember when every API started with a controller folder? Those days might be numbered. Hono's documentation has a bit of a silent killer in its best practices which make it clear: they don't belong in modern JavaScript apps. It's an interesting stance. Controllers used to feel like the gold standard for structuring HTTP logic. They brought order, separation, and a sense of architecture. But maybe that era's ending? In Conversation Piece's debut alongside the Hustle Hammer series, I dig into whether the controller pattern still earns its keep in 2025 - or if frameworks like Hono are showing us a better way to think about routing and request handling. Give it a read and tell me where you stand: are controllers still part of your toolkit, or are you moving on? https://lnkd.in/e8tNRsYw
To view or add a comment, sign in
-
🚀 Heard of Arrow Functions — the improvised version of regular functions? That’s true! They make code concise and cleaner — no wonder developers love them 😎 But let’s uncover a hidden drawback most overlook 👇 ⚡️ What’s really behind an Arrow Function? 👉 An arrow function is actually an anonymous function assigned to a variable. 👉 Since it’s just a function expression, it can’t be called before its definition (unlike regular functions). 🧩 Try it yourself: dummyFunction(); let dummyFunction = () => console.log("Hello User!"); 💥 Output: ReferenceError – dummyFunction is not defined 👉 Why? Because let and const are hoisted but stay in the Temporal Dead Zone (TDZ) until their declaration line is executed. 💡 Now with var: dummyFunction(); var dummyFunction = () => console.log("Hello User!"); 💥 Output: TypeError – dummyFunction is not a function Here’s why: 👉 var is hoisted and initialized with undefined. 👉 During the call, it’s as if you wrote undefined(); 👉 Since undefined isn’t callable, JS throws a TypeError. 🔖 #JavaScript #WebDevelopment #Frontend #CodeTips #JSCommunity #LearningJavaScript #DevCommunity #WebDev #CodingJourney
To view or add a comment, sign in
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development