JavaScript Array Trick: Accessing Out of Bounds Index

JavaScript Array Trick (Most Devs Miss This!) Problem: let arr = [1, 2, 3, 4, 5]; arr[10] = 42; console.log(arr); console.log(arr.length); What will be the output? #javascript #mern #webdevelopment #coding #developer

✅ Answer: [1, 2, 3, 4, 5, empty × 5, 42] 11 JS creates empty slots (sparse array) - not undefined. Methods like map() skip these slots. Tip: Avoid sparse arrays in real projects.

Like
Reply

To view or add a comment, sign in

Explore content categories