JavaScript Array Delete Explanation

🚀 Day 29 - 💡 JavaScript Tricky Question Explanation let a = [1,2,3]; delete a[1]; console.log(a); console.log(a.length); 👉 Output: ``` [1, empty, 3] 3 ``` 👉 Explanation: * `delete` removes the value but does NOT reindex the array * It creates a hole (empty slot) instead of shifting elements * So, `length` remains 3 ⚠️ Use `splice()` if you want to remove and shift elements #JavaScript #WebDevelopment #Frontend #CodingInterview #JSConcepts

To view or add a comment, sign in

Explore content categories